├── Analyser.pas ├── CompilerUtils.pas ├── D7Grammar.txt ├── Doc ├── PPT LLVM-Pascal.pdf └── TCC LLVM-Pascal.pdf ├── Generator.pas ├── Grammar.pas ├── Install ├── Content │ ├── BinUtils │ │ ├── ar.exe │ │ ├── as.exe │ │ ├── ld.exe │ │ ├── objdump.exe │ │ ├── strip.exe │ │ └── windres.exe │ ├── LLVM-3.1.x86.dll │ ├── LLVM-3.1.x86_64.dll │ └── LLVM │ │ ├── LTO.dll │ │ ├── bugpoint.exe │ │ ├── llc.exe │ │ ├── lli.exe │ │ ├── llvm-ar.exe │ │ ├── llvm-as.exe │ │ ├── llvm-bcanalyzer.exe │ │ ├── llvm-config.exe │ │ ├── llvm-cov.exe │ │ ├── llvm-diff.exe │ │ ├── llvm-dis.exe │ │ ├── llvm-dwarfdump.exe │ │ ├── llvm-extract.exe │ │ ├── llvm-ld.exe │ │ ├── llvm-link.exe │ │ ├── llvm-mc.exe │ │ ├── llvm-nm.exe │ │ ├── llvm-objdump.exe │ │ ├── llvm-prof.exe │ │ ├── llvm-ranlib.exe │ │ ├── llvm-readobj.exe │ │ ├── llvm-rtdyld.exe │ │ ├── llvm-size.exe │ │ ├── llvm-stress.exe │ │ ├── llvm-stub.exe │ │ ├── llvm-tblgen.exe │ │ ├── macho-dump.exe │ │ └── opt.exe ├── LLVMPascal.iss └── Output │ └── LLVMPascalSetup.exe ├── LLVMLibraries.zip ├── LLVM_Pascal.bdsproj ├── LLVM_Pascal.bnf ├── LLVM_Pascal.cfg ├── LLVM_Pascal.dpr ├── LLVM_Pascal.dproj ├── Parser.pas ├── Pesquisa ├── C_in_FreePascal.pdf ├── LazarusPorting.pdf ├── ObjM2-Grammar.pdf ├── ToyPascal │ ├── LLVM_reference │ │ ├── add.txt │ │ ├── for.txt │ │ ├── if.txt │ │ ├── if_while.txt │ │ ├── putchar.txt │ │ ├── sub.txt │ │ ├── test.ll │ │ └── while.txt │ ├── Makefile │ ├── ast.c │ ├── ast.h │ ├── base.c │ ├── base.h │ ├── c_codegen_visitor.c │ ├── c_codegen_visitor.h │ ├── graphprinter_visitor.c │ ├── graphprinter_visitor.h │ ├── lextest.l │ ├── llvm_codegen_visitor.c │ ├── llvm_codegen_visitor.h │ ├── parser.y │ ├── pascal │ │ ├── constants.pas │ │ ├── for.pas │ │ ├── helloworld.pas │ │ ├── if.pas │ │ ├── ifandelze.pas │ │ ├── sample0.pas │ │ ├── sample1.pas │ │ ├── sample2.pas │ │ ├── sample3.pas │ │ ├── sample4.pas │ │ ├── sample5.pas │ │ ├── variaveis.pas │ │ ├── variaveis2.pas │ │ └── while.pas │ ├── scanner.l │ ├── simpleprinter_visitor.c │ ├── simpleprinter_visitor.h │ ├── symbol_table.c │ ├── symbol_table.h │ ├── typecheck_visitor.c │ └── typecheck_visitor.h ├── Writing a compiler using Python, Lex, Yacc and LLVM by Alcides Fonseca.htm ├── Writing a compiler using Python, Lex, Yacc and LLVM by Alcides Fonseca_arquivos │ ├── alcides-bliki.css │ ├── alcides_small.png │ ├── auryn1gif1_normal.png │ ├── avatar92.jpg │ ├── avatar92_002.jpg │ ├── avatar92_003.jpg │ ├── avatar92_004.jpg │ ├── bullet-feed.png │ ├── disqus-logo.png │ ├── email.png │ ├── embed.js │ ├── facebook.png │ ├── general.js │ ├── hackernews.png │ ├── hackernews_128.png │ ├── jsserv.htm │ ├── login-disqus.gif │ ├── login-openid.gif │ ├── login-twitter.gif │ ├── me_normal.xml │ ├── moderator.png │ ├── narcissus.css │ ├── narcissus.js │ ├── noavatar92.png │ ├── reply.htm │ ├── reply_data │ │ ├── ga.js │ │ ├── httpjson.js │ │ └── quant.js │ ├── styles.css │ ├── syntax.css │ ├── thread.css │ ├── twitter.png │ ├── twitterProfilePhoto_normal.xml │ └── twitter_002.png ├── WritingYourCompilerUsingLLVM.htm ├── WritingYourCompilerUsingLLVM_arquivos │ ├── 134242.js │ ├── 6460_549798407904_48300380_33486194_6308796_n_bigger.jpg │ ├── ClassDiagram.png │ ├── ads.htm │ ├── ads_data │ │ ├── abg-en-100c-000000.png │ │ ├── graphics.js │ │ └── sma8.js │ ├── expansion_embed.js │ ├── ga.js │ ├── highlight.js │ ├── image.png │ ├── image1.png │ ├── jquery.js │ ├── pipeline.png │ ├── show_ads.js │ ├── style.css │ ├── test_domain.js │ └── twitter.js ├── d-pldi06.pdf └── tcc-eduardo-mello-cantu_v2.pdf ├── Scanner.pas ├── SymbolTable.pas ├── TestSuite ├── Test01.pas ├── Test02.pas ├── Test03.pas ├── Test04.pas ├── Test05.pas ├── Test06.pas ├── Test07.pas ├── Test08.pas ├── Test09.pas ├── Test10.pas ├── Test11.pas ├── Test12.pas ├── Test13.pas ├── Test14.pas └── Test15.pas ├── Token.pas ├── imagens ├── Cheetah_Dragon_by_Demon_of_night_wings.jpg └── Spotted_Dragon_Line_Art_by_Demon_of_night_wings.jpg ├── llvmAPI.pas ├── llvmTriple.pas └── readme.txt /Analyser.pas: -------------------------------------------------------------------------------- 1 | unit Analyser; 2 | 3 | interface 4 | 5 | uses 6 | Parser, SymbolTable, Token; 7 | 8 | type 9 | TAnalyser = class(TParser) 10 | public 11 | constructor Create(MaxErrors : integer = 10 ; Includes : AnsiString = ''; SilentMode : integer = 2 ; 12 | LanguageMode : AnsiString = ''; NotShow : AnsiString = ''); 13 | protected 14 | SymbolTable : TSymbolTable; 15 | Operand : TToken; 16 | procedure Analyse(Symbol : char); override; 17 | procedure PushScope; 18 | procedure PopScope; 19 | procedure AddModule; 20 | procedure AddSymbol; 21 | procedure SetType; 22 | procedure GetSymbol; 23 | end; 24 | 25 | implementation 26 | 27 | uses 28 | CompilerUtils;//, Generator; 29 | 30 | const 31 | SemanticAction : array[#0..#5] of pointer = ( 32 | @TAnalyser.PushScope, @TAnalyser.PopScope, @TAnalyser.AddModule, @TAnalyser.AddSymbol, 33 | @TAnalyser.SetType, @TAnalyser.GetSymbol); 34 | 35 | constructor TAnalyser.Create(MaxErrors : integer; Includes : AnsiString; SilentMode : integer; LanguageMode : AnsiString; 36 | NotShow : AnsiString); 37 | begin 38 | inherited; 39 | SymbolTable := TSymbolTable.Create; 40 | end; 41 | 42 | procedure TAnalyser.Analyse(Symbol : char); begin 43 | Call(SemanticAction, Symbol); 44 | end; 45 | 46 | procedure TAnalyser.PushScope; begin 47 | SymbolTable.PushScope; 48 | end; 49 | 50 | procedure TAnalyser.PopScope; begin 51 | try 52 | SymbolTable.PopScope; 53 | except 54 | on E : EFatal do ShowMessage('Fatal', E.Message); 55 | end; 56 | end; 57 | 58 | procedure TAnalyser.AddModule; begin 59 | Token.Kind := StringToTokenKind(LastLexeme); 60 | //MakeModule(Token); 61 | AddSymbol; 62 | end; 63 | 64 | procedure TAnalyser.AddSymbol; begin 65 | try 66 | SymbolTable.Add(Token); 67 | Token := TToken.Create; 68 | except 69 | on E : EFatal do ShowMessage('Fatal', E.Message); 70 | on E : EError do Error(E.Message); 71 | end; 72 | end; 73 | 74 | procedure TAnalyser.SetType; 75 | var 76 | T : TToken; 77 | L : string; 78 | begin 79 | L := Token.Lexeme; 80 | T := SymbolTable.Last; 81 | while (T <> nil) and (T.Kind = tkIdentifier) do begin 82 | T.Type_ := SymbolTable.Get(L); 83 | if T.Type_ = nil then T.Kind := StringToTokenKind(L, tkIdentifier); 84 | T := SymbolTable.Previous; 85 | end; 86 | end; 87 | 88 | procedure TAnalyser.GetSymbol; begin 89 | Operand := SymbolTable.Get(Token.Lexeme); 90 | if Operand = nil then Error('Undeclared Identifier "' + Token.Lexeme + '"'); 91 | end; 92 | 93 | end. 94 | -------------------------------------------------------------------------------- /CompilerUtils.pas: -------------------------------------------------------------------------------- 1 | unit CompilerUtils; 2 | 3 | interface 4 | 5 | uses 6 | SysUtils, Parser; 7 | 8 | type 9 | EHint = Exception; 10 | EWarning = class(EHint); 11 | EError = class(EWarning); 12 | EFatal = class(EError); 13 | 14 | function ReadSwitch(Switches : array of AnsiString) : AnsiString; overload; 15 | function ReadSwitch(Switches : array of AnsiString; Default : integer) : integer; overload; 16 | procedure CompilePath(Compiler : TParser; Path : AnsiString); 17 | procedure CompileTree(Compiler : TParser; Tree : AnsiString); 18 | 19 | implementation 20 | 21 | function ReadSwitch(Switches : array of AnsiString) : AnsiString; 22 | var 23 | I, J : Integer; 24 | begin 25 | for I := 0 to high(Switches) do 26 | for J := 2 to ParamCount do 27 | if pos('-' + UpperCase(Switches[I]), UpperCase(ParamStr(J))) = 1 then begin 28 | Result := copy(ParamStr(J), length(Switches[I]) + 2, 100); 29 | exit; 30 | end; 31 | Result := ''; 32 | end; 33 | 34 | function ReadSwitch(Switches : array of AnsiString; Default : Integer) : Integer; 35 | var 36 | I, J : Integer; 37 | begin 38 | for I := 0 to high(Switches) do 39 | for J := 2 to ParamCount do 40 | if pos('-' + UpperCase(Switches[I]), UpperCase(ParamStr(J))) = 1 then begin 41 | Result := StrToIntDef(copy(ParamStr(J), length(Switches[I]) + 2, 100), Default); 42 | exit; 43 | end; 44 | Result := Default; 45 | end; 46 | 47 | procedure CompilePath(Compiler : TParser; Path : AnsiString); 48 | var 49 | F : TSearchRec; 50 | begin 51 | try 52 | if FindFirst(Path, faAnyFile, F) = 0 then 53 | repeat 54 | Compiler.Compile(ExtractFilePath(Path) + F.Name); 55 | until FindNext(F) <> 0; 56 | finally 57 | FindClose(F) 58 | end; 59 | end; 60 | 61 | procedure CompileTree(Compiler : TParser; Tree : AnsiString); 62 | var 63 | Path, Ext : AnsiString; 64 | F : TSearchRec; 65 | begin 66 | if pos('*', Tree) <> 0 then begin 67 | Path := ExtractFilePath(Tree); 68 | Ext := ExtractFileName(Tree); 69 | if Compiler.SilentMode >= 2 then WriteLn(Path); 70 | end; 71 | CompilePath(Compiler, Tree); 72 | try 73 | if pos('*', Tree) <> 0 then 74 | try 75 | if FindFirst(Path + '*', faDirectory, F) = 0 then begin 76 | while pos('.', F.Name) <> 0 do 77 | if FindNext(F) <> 0 then exit; 78 | repeat 79 | if pos('.', F.Name) = 0 then CompileTree(Compiler, Path + F.Name + PathDelim + Ext); 80 | until FindNext(F) <> 0; 81 | end; 82 | finally 83 | FindClose(F) 84 | end; 85 | except 86 | end; 87 | end; 88 | 89 | end. 90 | 91 | -------------------------------------------------------------------------------- /Doc/PPT LLVM-Pascal.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wanderlan/llvm-pascal/19fda52906749ee0bd05d0e0c1d81d2806b7d263/Doc/PPT LLVM-Pascal.pdf -------------------------------------------------------------------------------- /Doc/TCC LLVM-Pascal.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wanderlan/llvm-pascal/19fda52906749ee0bd05d0e0c1d81d2806b7d263/Doc/TCC LLVM-Pascal.pdf -------------------------------------------------------------------------------- /Generator.pas: -------------------------------------------------------------------------------- 1 | unit Generator; 2 | 3 | interface 4 | 5 | uses 6 | Analyser, Token; 7 | 8 | type 9 | TGenerator = class helper for TAnalyser 10 | protected 11 | // procedure Generate(Symbol : char); override; 12 | public 13 | procedure MakeModule(Token : TToken); 14 | end; 15 | 16 | implementation 17 | 18 | uses 19 | Scanner, llvmAPI; 20 | 21 | (*const 22 | GeneratorAction : array[#0..#1] of pointer = (@TGenerator.Generate, nil); 23 | 24 | procedure TGenerator.Generate(Symbol : char); begin 25 | Call(GeneratorAction, Symbol); 26 | end; 27 | *) 28 | procedure TGenerator.MakeModule(Token : TToken); 29 | var 30 | Module: LLVMModuleRef; 31 | ArrayTy_0, PointerTy_1, FuncTy_2, PointerTy_3, FuncTy_5, PointerTy_4: LLVMTypeRef; 32 | FyncTy_2_Args: array [0..0] of LLVMTypeRef; 33 | FyncTy_5_Args: array [0..0] of LLVMTypeRef; 34 | func_main, func_puts, gvar_array_str, const_array_6, int32_puts, 35 | const_ptr_7, const_int32_9, const_int64_8: LLVMValueRef; 36 | const_ptr_7_indices: array [0..1] of LLVMValueRef; 37 | label_10: LLVMBasicBlockRef; 38 | Builder: LLVMBuilderRef; 39 | Context: LLVMContextRef; 40 | begin 41 | Module := LLVMModuleCreateWithName(PChar((*Path*)Token.Lexeme + '.bc')); 42 | LLVMSetDataLayout(Module, 43 | 'e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64-S128'); 44 | LLVMSetTarget(Module, TargetCPU + '-unknown-' + TargetOS); 45 | Context := LLVMGetModuleContext(Module); 46 | // Type Definitions 47 | ArrayTy_0 := LLVMArrayType(LLVMInt8TypeInContext(Context), 12); 48 | PointerTy_1 := LLVMPointerType(ArrayTy_0, 0); 49 | FuncTy_2 := LLVMFunctionType(LLVMInt32TypeInContext(Context), @FyncTy_2_Args[0], 0, LLVMFalse); 50 | PointerTy_3 := LLVMPointerType(LLVMInt8TypeInContext(Context), 0); 51 | FyncTy_5_Args[0] := PointerTy_3; 52 | FuncTy_5 := LLVMFunctionType(LLVMInt32TypeInContext(Context), @FyncTy_5_Args[0], 1, LLVMFalse); 53 | PointerTy_4 := LLVMPointerType(FuncTy_5, 0); 54 | 55 | func_main := LLVMGetNamedFunction(Module, 'main'); 56 | if func_main = nil then begin 57 | func_main := LLVMAddFunction(Module, 'main', FuncTy_2); 58 | LLVMSetLinkage(func_main, LLVMExternalLinkage); 59 | LLVMSetFunctionCallConv(func_main, Ord(LLVMCCallConv)); { BAD IDEA } 60 | end; 61 | LLVMAddFunctionAttr(func_main, LLVMNoUnwindAttribute); 62 | LLVMAddFunctionAttr(func_main, LLVMUWTable); 63 | 64 | func_puts := LLVMGetNamedFunction(Module, 'puts'); 65 | if func_puts = nil then begin 66 | func_puts := LLVMAddFunction(Module, 'puts', FuncTy_5); 67 | LLVMSetLinkage(func_puts, LLVMExternalLinkage); 68 | LLVMSetFunctionCallConv(func_puts, Ord(LLVMCCallConv)); 69 | end; 70 | LLVMAddFunctionAttr(func_puts, LLVMNoUnwindAttribute); 71 | 72 | // Global Variable Declarations 73 | gvar_array_str := LLVMAddGlobal(Module, ArrayTy_0, 'str'); 74 | LLVMSetLinkage(gvar_array_str, LLVMInternalLinkage); 75 | LLVMSetGlobalConstant(gvar_array_str, LLVMTrue); 76 | // Constant Definitions 77 | const_array_6 := LLVMConstStringInContext(Context, 'Hello World'#0, 12, LLVMTrue); {?} 78 | const_int64_8 := LLVMConstIntOfString(LLVMInt64TypeInContext(Context), '0', 10); //LLVMConstIntOfArbitraryPrecision(LLVMInt64TypeInContext(Context), 10, nil); 79 | const_ptr_7_indices[0] := const_int64_8; 80 | const_ptr_7_indices[1] := const_int64_8; 81 | const_ptr_7 := LLVMConstGEP(gvar_array_str, @const_ptr_7_indices[0], 2); 82 | const_int32_9 := LLVMConstIntOfString(LLVMInt32TypeInContext(Context), '0', 10); //LLVMConstIntOfArbitraryPrecision(LLVMInt32TypeInContext(Context), 10, nil); 83 | 84 | // Global Variable Definitions 85 | LLVMSetInitializer(gvar_array_str, const_array_6); 86 | 87 | // Function Definitions 88 | label_10 := LLVMAppendBasicBlockInContext(Context, func_main, ''); 89 | Builder := LLVMCreateBuilder(); 90 | LLVMPositionBuilderAtEnd(Builder, label_10); 91 | int32_puts := LLVMBuildCall(Builder, func_puts, const_ptr_7, 1, 'puts'); 92 | LLVMSetInstructionCallConv(int32_puts, Ord(LLVMCCallConv)); 93 | LLVMSetTailCall(int32_puts, LLVMTrue); 94 | LLVMBuildRet(Builder, const_int32_9); 95 | end; 96 | 97 | end. 98 | 99 | -------------------------------------------------------------------------------- /Install/Content/BinUtils/ar.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wanderlan/llvm-pascal/19fda52906749ee0bd05d0e0c1d81d2806b7d263/Install/Content/BinUtils/ar.exe -------------------------------------------------------------------------------- /Install/Content/BinUtils/as.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wanderlan/llvm-pascal/19fda52906749ee0bd05d0e0c1d81d2806b7d263/Install/Content/BinUtils/as.exe -------------------------------------------------------------------------------- /Install/Content/BinUtils/ld.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wanderlan/llvm-pascal/19fda52906749ee0bd05d0e0c1d81d2806b7d263/Install/Content/BinUtils/ld.exe -------------------------------------------------------------------------------- /Install/Content/BinUtils/objdump.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wanderlan/llvm-pascal/19fda52906749ee0bd05d0e0c1d81d2806b7d263/Install/Content/BinUtils/objdump.exe -------------------------------------------------------------------------------- /Install/Content/BinUtils/strip.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wanderlan/llvm-pascal/19fda52906749ee0bd05d0e0c1d81d2806b7d263/Install/Content/BinUtils/strip.exe -------------------------------------------------------------------------------- /Install/Content/BinUtils/windres.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wanderlan/llvm-pascal/19fda52906749ee0bd05d0e0c1d81d2806b7d263/Install/Content/BinUtils/windres.exe -------------------------------------------------------------------------------- /Install/Content/LLVM-3.1.x86.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wanderlan/llvm-pascal/19fda52906749ee0bd05d0e0c1d81d2806b7d263/Install/Content/LLVM-3.1.x86.dll -------------------------------------------------------------------------------- /Install/Content/LLVM-3.1.x86_64.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wanderlan/llvm-pascal/19fda52906749ee0bd05d0e0c1d81d2806b7d263/Install/Content/LLVM-3.1.x86_64.dll -------------------------------------------------------------------------------- /Install/Content/LLVM/LTO.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wanderlan/llvm-pascal/19fda52906749ee0bd05d0e0c1d81d2806b7d263/Install/Content/LLVM/LTO.dll -------------------------------------------------------------------------------- /Install/Content/LLVM/bugpoint.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wanderlan/llvm-pascal/19fda52906749ee0bd05d0e0c1d81d2806b7d263/Install/Content/LLVM/bugpoint.exe -------------------------------------------------------------------------------- /Install/Content/LLVM/llc.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wanderlan/llvm-pascal/19fda52906749ee0bd05d0e0c1d81d2806b7d263/Install/Content/LLVM/llc.exe -------------------------------------------------------------------------------- /Install/Content/LLVM/lli.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wanderlan/llvm-pascal/19fda52906749ee0bd05d0e0c1d81d2806b7d263/Install/Content/LLVM/lli.exe -------------------------------------------------------------------------------- /Install/Content/LLVM/llvm-ar.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wanderlan/llvm-pascal/19fda52906749ee0bd05d0e0c1d81d2806b7d263/Install/Content/LLVM/llvm-ar.exe -------------------------------------------------------------------------------- /Install/Content/LLVM/llvm-as.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wanderlan/llvm-pascal/19fda52906749ee0bd05d0e0c1d81d2806b7d263/Install/Content/LLVM/llvm-as.exe -------------------------------------------------------------------------------- /Install/Content/LLVM/llvm-bcanalyzer.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wanderlan/llvm-pascal/19fda52906749ee0bd05d0e0c1d81d2806b7d263/Install/Content/LLVM/llvm-bcanalyzer.exe -------------------------------------------------------------------------------- /Install/Content/LLVM/llvm-config.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wanderlan/llvm-pascal/19fda52906749ee0bd05d0e0c1d81d2806b7d263/Install/Content/LLVM/llvm-config.exe -------------------------------------------------------------------------------- /Install/Content/LLVM/llvm-cov.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wanderlan/llvm-pascal/19fda52906749ee0bd05d0e0c1d81d2806b7d263/Install/Content/LLVM/llvm-cov.exe -------------------------------------------------------------------------------- /Install/Content/LLVM/llvm-diff.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wanderlan/llvm-pascal/19fda52906749ee0bd05d0e0c1d81d2806b7d263/Install/Content/LLVM/llvm-diff.exe -------------------------------------------------------------------------------- /Install/Content/LLVM/llvm-dis.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wanderlan/llvm-pascal/19fda52906749ee0bd05d0e0c1d81d2806b7d263/Install/Content/LLVM/llvm-dis.exe -------------------------------------------------------------------------------- /Install/Content/LLVM/llvm-dwarfdump.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wanderlan/llvm-pascal/19fda52906749ee0bd05d0e0c1d81d2806b7d263/Install/Content/LLVM/llvm-dwarfdump.exe -------------------------------------------------------------------------------- /Install/Content/LLVM/llvm-extract.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wanderlan/llvm-pascal/19fda52906749ee0bd05d0e0c1d81d2806b7d263/Install/Content/LLVM/llvm-extract.exe -------------------------------------------------------------------------------- /Install/Content/LLVM/llvm-ld.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wanderlan/llvm-pascal/19fda52906749ee0bd05d0e0c1d81d2806b7d263/Install/Content/LLVM/llvm-ld.exe -------------------------------------------------------------------------------- /Install/Content/LLVM/llvm-link.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wanderlan/llvm-pascal/19fda52906749ee0bd05d0e0c1d81d2806b7d263/Install/Content/LLVM/llvm-link.exe -------------------------------------------------------------------------------- /Install/Content/LLVM/llvm-mc.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wanderlan/llvm-pascal/19fda52906749ee0bd05d0e0c1d81d2806b7d263/Install/Content/LLVM/llvm-mc.exe -------------------------------------------------------------------------------- /Install/Content/LLVM/llvm-nm.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wanderlan/llvm-pascal/19fda52906749ee0bd05d0e0c1d81d2806b7d263/Install/Content/LLVM/llvm-nm.exe -------------------------------------------------------------------------------- /Install/Content/LLVM/llvm-objdump.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wanderlan/llvm-pascal/19fda52906749ee0bd05d0e0c1d81d2806b7d263/Install/Content/LLVM/llvm-objdump.exe -------------------------------------------------------------------------------- /Install/Content/LLVM/llvm-prof.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wanderlan/llvm-pascal/19fda52906749ee0bd05d0e0c1d81d2806b7d263/Install/Content/LLVM/llvm-prof.exe -------------------------------------------------------------------------------- /Install/Content/LLVM/llvm-ranlib.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wanderlan/llvm-pascal/19fda52906749ee0bd05d0e0c1d81d2806b7d263/Install/Content/LLVM/llvm-ranlib.exe -------------------------------------------------------------------------------- /Install/Content/LLVM/llvm-readobj.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wanderlan/llvm-pascal/19fda52906749ee0bd05d0e0c1d81d2806b7d263/Install/Content/LLVM/llvm-readobj.exe -------------------------------------------------------------------------------- /Install/Content/LLVM/llvm-rtdyld.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wanderlan/llvm-pascal/19fda52906749ee0bd05d0e0c1d81d2806b7d263/Install/Content/LLVM/llvm-rtdyld.exe -------------------------------------------------------------------------------- /Install/Content/LLVM/llvm-size.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wanderlan/llvm-pascal/19fda52906749ee0bd05d0e0c1d81d2806b7d263/Install/Content/LLVM/llvm-size.exe -------------------------------------------------------------------------------- /Install/Content/LLVM/llvm-stress.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wanderlan/llvm-pascal/19fda52906749ee0bd05d0e0c1d81d2806b7d263/Install/Content/LLVM/llvm-stress.exe -------------------------------------------------------------------------------- /Install/Content/LLVM/llvm-stub.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wanderlan/llvm-pascal/19fda52906749ee0bd05d0e0c1d81d2806b7d263/Install/Content/LLVM/llvm-stub.exe -------------------------------------------------------------------------------- /Install/Content/LLVM/llvm-tblgen.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wanderlan/llvm-pascal/19fda52906749ee0bd05d0e0c1d81d2806b7d263/Install/Content/LLVM/llvm-tblgen.exe -------------------------------------------------------------------------------- /Install/Content/LLVM/macho-dump.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wanderlan/llvm-pascal/19fda52906749ee0bd05d0e0c1d81d2806b7d263/Install/Content/LLVM/macho-dump.exe -------------------------------------------------------------------------------- /Install/Content/LLVM/opt.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wanderlan/llvm-pascal/19fda52906749ee0bd05d0e0c1d81d2806b7d263/Install/Content/LLVM/opt.exe -------------------------------------------------------------------------------- /Install/LLVMPascal.iss: -------------------------------------------------------------------------------- 1 | ; Script generated by the Inno Setup Script Wizard. 2 | ; SEE THE DOCUMENTATION FOR DETAILS ON CREATING INNO SETUP SCRIPT FILES! 3 | 4 | #define MyAppName "LLVM-Pascal" 5 | #define MyAppVersion "3.1.1" 6 | #define MyAppPublisher "LLVM-Pascal Team" 7 | #define MyAppURL "http://code.google.com/p/llvm-pascal/" 8 | 9 | [Setup] 10 | ; NOTE: The value of AppId uniquely identifies this application. 11 | ; Do not use the same AppId value in installers for other applications. 12 | ; (To generate a new GUID, click Tools | Generate GUID inside the IDE.) 13 | AppID={{AF246CE2-015E-4C80-850A-0314C4E5411B} 14 | AppName={#MyAppName} 15 | AppVersion={#MyAppVersion} 16 | AppVerName={#MyAppName} {#MyAppVersion} 17 | AppPublisher={#MyAppPublisher} 18 | AppPublisherURL={#MyAppURL} 19 | AppSupportURL={#MyAppURL} 20 | AppUpdatesURL={#MyAppURL} 21 | DefaultDirName={pf}\{#MyAppName} 22 | DefaultGroupName={#MyAppName} 23 | AllowNoIcons=true 24 | OutputDir=.\Output\ 25 | OutputBaseFilename=LLVMPascalSetup 26 | Compression=lzma2/Ultra 27 | SolidCompression=true 28 | UninstallDisplayName={#MyAppName} 29 | 30 | [Languages] 31 | Name: "english"; MessagesFile: "compiler:Default.isl" 32 | Name: "basque"; MessagesFile: "compiler:Languages\Basque.isl" 33 | Name: "brazilianportuguese"; MessagesFile: "compiler:Languages\BrazilianPortuguese.isl" 34 | Name: "catalan"; MessagesFile: "compiler:Languages\Catalan.isl" 35 | Name: "czech"; MessagesFile: "compiler:Languages\Czech.isl" 36 | Name: "danish"; MessagesFile: "compiler:Languages\Danish.isl" 37 | Name: "dutch"; MessagesFile: "compiler:Languages\Dutch.isl" 38 | Name: "finnish"; MessagesFile: "compiler:Languages\Finnish.isl" 39 | Name: "french"; MessagesFile: "compiler:Languages\French.isl" 40 | Name: "german"; MessagesFile: "compiler:Languages\German.isl" 41 | Name: "hebrew"; MessagesFile: "compiler:Languages\Hebrew.isl" 42 | Name: "hungarian"; MessagesFile: "compiler:Languages\Hungarian.isl" 43 | Name: "italian"; MessagesFile: "compiler:Languages\Italian.isl" 44 | Name: "japanese"; MessagesFile: "compiler:Languages\Japanese.isl" 45 | Name: "norwegian"; MessagesFile: "compiler:Languages\Norwegian.isl" 46 | Name: "polish"; MessagesFile: "compiler:Languages\Polish.isl" 47 | Name: "portuguese"; MessagesFile: "compiler:Languages\Portuguese.isl" 48 | Name: "russian"; MessagesFile: "compiler:Languages\Russian.isl" 49 | Name: "slovak"; MessagesFile: "compiler:Languages\Slovak.isl" 50 | Name: "slovenian"; MessagesFile: "compiler:Languages\Slovenian.isl" 51 | Name: "spanish"; MessagesFile: "compiler:Languages\Spanish.isl" 52 | 53 | [Files] 54 | ; LLVM libraries 55 | Source: ".\Content\LLVM-3.1.x86.dll"; DestDir: "{app}\"; Flags: ignoreversion 56 | Source: ".\Content\LLVM-3.1.x86_64.dll"; DestDir: "{app}\"; Flags: ignoreversion 57 | ; BinUtils 58 | Source: ".\Content\BinUtils\*"; DestDir: "{app}\BinUtils\"; Flags: ignoreversion 59 | ; LLVM Toolchain 60 | Source: ".\Content\LLVM\*"; DestDir: "{app}\LLVM\"; Flags: ignoreversion 61 | 62 | [Icons] 63 | Name: "{group}\{cm:ProgramOnTheWeb,{#MyAppName}}"; Filename: "{#MyAppURL}" 64 | Name: "{group}\{cm:UninstallProgram,{#MyAppName}}"; Filename: "{uninstallexe}" 65 | -------------------------------------------------------------------------------- /Install/Output/LLVMPascalSetup.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wanderlan/llvm-pascal/19fda52906749ee0bd05d0e0c1d81d2806b7d263/Install/Output/LLVMPascalSetup.exe -------------------------------------------------------------------------------- /LLVMLibraries.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wanderlan/llvm-pascal/19fda52906749ee0bd05d0e0c1d81d2806b7d263/LLVMLibraries.zip -------------------------------------------------------------------------------- /LLVM_Pascal.bnf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wanderlan/llvm-pascal/19fda52906749ee0bd05d0e0c1d81d2806b7d263/LLVM_Pascal.bnf -------------------------------------------------------------------------------- /LLVM_Pascal.cfg: -------------------------------------------------------------------------------- 1 | -$A1 2 | -$B- 3 | -$C- 4 | -$D+ 5 | -$E- 6 | -$F- 7 | -$G+ 8 | -$H+ 9 | -$I- 10 | -$J+ 11 | -$K- 12 | -$L+ 13 | -$M- 14 | -$N+ 15 | -$O+ 16 | -$P+ 17 | -$Q- 18 | -$R- 19 | -$S- 20 | -$T- 21 | -$U- 22 | -$V- 23 | -$W- 24 | -$X+ 25 | -$YD 26 | -$Z1 27 | -GD 28 | -cg 29 | -AWinTypes=Windows;WinProcs=Windows;DbiTypes=BDE;DbiProcs=BDE;DbiErrs=BDE; 30 | -H+ 31 | -W+ 32 | -M 33 | -$M16384,1048576 34 | -K$00400000 35 | -N0"dcu" 36 | -LE"C:\Users\Public\Documents\RAD Studio\5.0\Bpl" 37 | -LN"C:\Users\Public\Documents\RAD Studio\5.0\Dcp" 38 | -------------------------------------------------------------------------------- /LLVM_Pascal.dpr: -------------------------------------------------------------------------------- 1 | program LLVM_Pascal; 2 | { 3 | Author: Wanderlan Santos dos Anjos, wanderlan.anjos@gmail.com 4 | Author: Barbara A. B. dos Anjos, barbara.ab.anjos@gmail.com 5 | Advisor: Paulo Guilherme Freire, freire.brasilia@gmail.com 6 | Advisor: Joel Guilherme da Silva Filho, joel-iesb@joelguilherme.com 7 | Date: apr-2010 8 | License: BSD 9 | Based on Dragon Book 10 | Tests: 11 | "C:\Arquivos de programas\Borland\BDS\4.0\source\*.pas" -fi"C:\Arquivos de programas\Borland\BDS\4.0\source\dunit\contrib\dunitwizard\source\common\" -v0 12 | help: 13 | virtual site:http://lazarus-ccr.sourceforge.net/docs 14 | } 15 | {$APPTYPE CONSOLE} 16 | 17 | uses 18 | SysUtils, CompilerUtils, Scanner, Analyser; 19 | 20 | var 21 | Compiler : TAnalyser; 22 | 23 | begin 24 | if not FindCmdLineSwitch('v0') then begin 25 | writeln('LLVM-Pascal Version ', Version, ^J, 26 | '(c)2012 by'^J, 27 | 'Wanderlan Santos dos Anjos, Barbara A.B. dos Anjos, Aleksey A. Naumov and Joel Guilherme'^J, 28 | 'New BSD license'^J, 29 | 'http://llvm-pascal.googlecode.com'^J); 30 | end; 31 | if (ParamCount = 0) or FindCmdLineSwitch('h') or FindCmdLineSwitch('?') then 32 | writeln('Usage: LLVM_Pascal '^J, 33 | '[-Fi]'^J, 34 | '[-v]'^J, 35 | '[-vm]'^J, 36 | '[-Se]'^J, 37 | '[-M]') 38 | else begin 39 | Compiler := TAnalyser.Create(ReadSwitch(['Se'], 10), ReadSwitch(['I', 'Fi']), ReadSwitch(['v'], 2), ReadSwitch(['M']), ReadSwitch(['vm'])); 40 | try 41 | CompileTree(Compiler, ParamStr(1)); 42 | finally 43 | Compiler.Free; 44 | readln; 45 | end; 46 | end; 47 | end. 48 | -------------------------------------------------------------------------------- /LLVM_Pascal.dproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | {F4BCB2DF-0E28-4179-A381-C0C6A4CDAA72} 4 | LLVM_Pascal.dpr 5 | True 6 | Debug 7 | 1 8 | Console 9 | None 10 | 13.4 11 | Win32 12 | 13 | 14 | true 15 | 16 | 17 | true 18 | Base 19 | true 20 | 21 | 22 | true 23 | Base 24 | true 25 | 26 | 27 | true 28 | Base 29 | true 30 | 31 | 32 | 00400000 33 | false 34 | CompanyName=;FileDescription=;FileVersion=1.0.0.0;InternalName=;LegalCopyright=;LegalTrademarks=;OriginalFilename=;ProductName=;ProductVersion=1.0.0.0;Comments= 35 | vclx;vcl;rtl;dbrtl;vcldb;dbxcds;dbexpress;dsnap;bdertl;teeui;teedb;tee;vcldbx;vclactnband;SignalLabGenericBasicPkgD10;SignalLabBasicPkgD10;OpenWirePkgD10;AudioLabGenericBasicPkgD10;AudioLabBasicPkgD10;SignalLabAdditionalPkgD10;SignalLabScopePkgD10;TimingLabBasicPkgD10;MediaLabBasicPkgD10;AudioLabEssentialPkgD10;AudioLabPkgD10;xmlrtl;AudioLabDsnD10;$(DCC_UsePackage) 36 | 1 37 | false 38 | true 39 | 3 40 | System;Xml;Data;Datasnap;Web;Soap;$(DCC_Namespace) 41 | false 42 | false 43 | false 44 | true 45 | false 46 | false 47 | 1 48 | 1046 49 | dcu 50 | 51 | 52 | Winapi;System.Win;Data.Win;Datasnap.Win;Web.Win;Soap.Win;Xml.Win;Bde;$(DCC_Namespace) 53 | CompanyName=;FileDescription=;FileVersion=1.0.0.0;InternalName=;LegalCopyright=;LegalTrademarks=;OriginalFilename=;ProductName=;ProductVersion=1.0.0.0;Comments= 54 | 1033 55 | 56 | 57 | false 58 | false 59 | 0 60 | RELEASE;$(DCC_Define) 61 | 62 | 63 | DEBUG;$(DCC_Define) 64 | false 65 | true 66 | 67 | 68 | 69 | MainSource 70 | 71 | 72 | Cfg_2 73 | Base 74 | 75 | 76 | Base 77 | 78 | 79 | Cfg_1 80 | Base 81 | 82 | 83 | 84 | Delphi.Personality.12 85 | VCLApplication 86 | 87 | 88 | 89 | LLVM_Pascal.dpr 90 | 91 | 92 | False 93 | False 94 | 1 95 | 0 96 | 0 97 | 0 98 | False 99 | False 100 | False 101 | False 102 | False 103 | 1046 104 | 1252 105 | 106 | 107 | 108 | 109 | 1.0.0.0 110 | 111 | 112 | 113 | 114 | 115 | 1.0.0.0 116 | 117 | 118 | 119 | 120 | False 121 | False 122 | True 123 | 124 | 125 | 12 126 | 127 | 128 | 129 | 130 | -------------------------------------------------------------------------------- /Parser.pas: -------------------------------------------------------------------------------- 1 | unit Parser; 2 | { 3 | Author: Wanderlan Santos dos Anjos, wanderlan.anjos@gmail.com 4 | Date: jan-2010 5 | License: BSD 6 | } 7 | interface 8 | 9 | uses 10 | Scanner; 11 | 12 | type 13 | TSymbol = string[15]; 14 | TStack = array[1..100] of TSymbol; 15 | TParser = class(TScanner) 16 | private 17 | Symbol : TSymbol; 18 | Symbols : TStack; 19 | function GetProductionName(const P : AnsiString) : AnsiString; 20 | procedure ExpandProduction; inline; 21 | procedure PopSymbol; //inline; 22 | protected 23 | procedure Call(Operations : array of pointer; Op : char); 24 | procedure RecoverFromError(const Expected, Found : AnsiString); override; 25 | procedure Analyse(Symbol : char); virtual; abstract; 26 | // procedure Generate(Symbol : char); virtual; abstract; 27 | public 28 | procedure Compile(const Source : AnsiString); 29 | procedure Error(const Msg : AnsiString); override; 30 | end; 31 | 32 | implementation 33 | 34 | uses 35 | SysUtils, Math, Grammar, StrUtils, Token {$IFDEF UNICODE}, AnsiStrings{$ENDIF}; 36 | 37 | type 38 | TParserMethod = procedure of object; 39 | 40 | procedure TParser.PopSymbol; begin 41 | dec(Top); 42 | if Top >= 1 then begin 43 | Symbol := Symbols[Top]; 44 | case Symbol[1] of 45 | Mark, Require : PopSymbol; 46 | Pop : 47 | repeat 48 | while (Symbols[Top] <> Mark) and (Top > 2) do dec(Top); 49 | dec(Top); 50 | Symbol := Symbols[Top]; 51 | until Symbol[1] <> Pop; 52 | Skip : begin 53 | ShowMessage('Warning', Symbols[Top + 1] + ' construct is ignored'); 54 | dec(Top); 55 | Symbol := Symbols[Top]; 56 | while UpperCase(Token.Lexeme) <> Symbol do NextToken(true); 57 | end; 58 | end; 59 | end 60 | end; 61 | 62 | procedure TParser.Call(Operations : array of pointer; Op : char); 63 | var 64 | Method : TMethod; 65 | begin 66 | Method.Code := Operations[Ord(Op)]; 67 | Method.Data := Self; 68 | TParserMethod(Method); 69 | end; 70 | 71 | procedure TParser.RecoverFromError(const Expected, Found : AnsiString); begin 72 | inherited; 73 | if Top = 1 then 74 | FEndSource := true 75 | else begin 76 | repeat 77 | Top := LastGoodTop + 1; 78 | Symbol := Symbols[Top]; 79 | Token.Lexeme := UpperCase(Token.Lexeme); 80 | while (Symbol <> Token.Lexeme) and (Top > 1) do 81 | if (Symbol[1] = Syntatic) and (pos('{' + Token.Lexeme + '}', Productions[Symbol[2]]) <> 0) then 82 | break 83 | else 84 | PopSymbol; 85 | if (Top = 1) and not EndSource then NextToken; 86 | until (Top <> 1) or EndSource; 87 | inc(Top); 88 | end; 89 | end; 90 | 91 | procedure TParser.Compile(const Source : AnsiString); begin 92 | try 93 | SourceName := Source; 94 | Symbols[1] := Start; 95 | Symbol := Start; 96 | Top := 1; 97 | repeat 98 | case Symbol[1] of 99 | #0..#127 : MatchToken(Symbol); // Terminal 100 | Syntatic : ExpandProduction; 101 | Semantic : ;//Analyse(Symbol[2]); 102 | Generator : ;//Generate(Symbol[2]); 103 | InsertSemi : begin 104 | if DoNextToken then NextToken; 105 | dec(First, length(Token.Lexeme)); 106 | Token.Lexeme := ';'; 107 | Token.Kind := tkSpecialSymbol; 108 | end 109 | else // Other Terminal 110 | MatchTerminal(CharToTokenKind(Symbol[1])); 111 | end; 112 | PopSymbol; 113 | until EndSource or (Top < 1); 114 | except 115 | on E : EAbort do raise; 116 | on E : Exception do Error(E.Message + Format(':%d.%d', [Ord(Symbol[1]), Ord(Symbol[2])])); 117 | end; 118 | end; 119 | 120 | procedure TParser.Error(const Msg : AnsiString); 121 | var 122 | I : integer; 123 | begin 124 | inherited; 125 | exit; // Comment this line to debug the compiler 126 | for I := min(Top + 5, high(Symbols)) downto 2 do 127 | case Symbols[I][1] of 128 | #0..#127 : writeln(I, ': ', Symbols[I]); // Terminal 129 | Syntatic : writeln(I, ': #', Ord(Symbols[I][2]), ', ', GetProductionName(Productions[Symbols[I][2]])); // Production 130 | Skip : writeln(I, ': Skip'); 131 | Require : writeln(I, ': Require'); 132 | Mark : writeln(I, ': Mark'); 133 | Pop : writeln(I, ': Pop'); 134 | else 135 | writeln(I, ': ', Symbols[I], ': TRASH'); 136 | end; 137 | end; 138 | 139 | procedure TParser.ExpandProduction; 140 | var 141 | Production : AnsiString; 142 | P, TopAux, LenToken : integer; 143 | Aux : TStack; 144 | begin 145 | if DoNextToken then NextToken; 146 | if EndSource then exit; 147 | ErrorCode := Symbol[2]; 148 | Production := Productions[Symbol[2]]; 149 | LenToken := 1; 150 | case Token.Kind of 151 | tkIdentifier : begin 152 | P := pos('{' + Ident, Production); 153 | if P = 0 then begin 154 | P := pos('{' + UpperCase(Token.Lexeme) + '}', Production); // find FIRST terminal 155 | LenToken := length(Token.Lexeme); 156 | end 157 | end; 158 | tkReservedWord, tkSpecialSymbol : begin 159 | P := pos('{' + UpperCase(Token.Lexeme) + '}', Production); // find FIRST terminal 160 | LenToken := length(Token.Lexeme); 161 | end; 162 | else // tkStringConstant..tkRealConstant 163 | P := pos('{' + TokenKindToChar(Token.Kind) + '}', Production); 164 | end; 165 | if P <> 0 then begin 166 | dec(Top); 167 | TopAux := 1; 168 | Aux[1] := copy(Production, P + 1, LenToken); 169 | inc(P, LenToken + 2); 170 | while P <= length(Production) do begin 171 | case Production[P] of 172 | Syntatic..Generator : begin // Nonterminal 173 | inc(TopAux); 174 | Aux[TopAux] := Production[P] + Production[P+1]; 175 | inc(P); 176 | end; 177 | Ident..Pop : begin // Nonterminal 178 | inc(TopAux); 179 | Aux[TopAux] := Production[P]; 180 | end; 181 | '{' : break; // End production 182 | else 183 | if (Aux[TopAux] <> '') and (Aux[TopAux][1] >= Syntatic) then begin // begin terminal 184 | inc(TopAux); 185 | Aux[TopAux] := Production[P] 186 | end 187 | else begin // Terminal 188 | if Production[P-1] = '}' then begin 189 | inc(TopAux); 190 | Aux[TopAux] := ''; 191 | end; 192 | Aux[TopAux] := Aux[TopAux] + Production[P] 193 | end; 194 | end; 195 | inc(P) 196 | end; 197 | for TopAux := TopAux downto 1 do begin // push at reverse order 198 | inc(Top); 199 | Symbols[Top] := Aux[TopAux]; 200 | end; 201 | inc(Top); 202 | end 203 | else 204 | if (Top = 1) or (Symbols[Top+1] = Require) then 205 | RecoverFromError(GetProductionName(Production), Token.Lexeme); 206 | end; 207 | 208 | function TParser.GetProductionName(const P : AnsiString) : AnsiString; 209 | var 210 | I, J : integer; 211 | S : AnsiString; 212 | begin 213 | Result := ''; 214 | if P[1] = '{' then begin 215 | I := 2; 216 | repeat 217 | J := posex('}', P, I); 218 | S := copy(P, I, J-I); 219 | if S[1] > Start then 220 | S := GetNonTerminalName(S[1]) 221 | else 222 | S := '"' + S + '"'; 223 | if Result = '' then 224 | Result := S 225 | else 226 | Result := Result + ', ' + S; 227 | I := posex('{', P, J+1) + 1; 228 | until I = 1; 229 | I := LastDelimiter(',', Result); 230 | if I <> 0 then begin 231 | delete(Result, I, 2); 232 | insert(' or ', Result, I); 233 | end; 234 | end 235 | else 236 | Result := copy(P, 1, pos('{', P)-1); 237 | end; 238 | 239 | end. 240 | -------------------------------------------------------------------------------- /Pesquisa/C_in_FreePascal.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wanderlan/llvm-pascal/19fda52906749ee0bd05d0e0c1d81d2806b7d263/Pesquisa/C_in_FreePascal.pdf -------------------------------------------------------------------------------- /Pesquisa/LazarusPorting.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wanderlan/llvm-pascal/19fda52906749ee0bd05d0e0c1d81d2806b7d263/Pesquisa/LazarusPorting.pdf -------------------------------------------------------------------------------- /Pesquisa/ObjM2-Grammar.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wanderlan/llvm-pascal/19fda52906749ee0bd05d0e0c1d81d2806b7d263/Pesquisa/ObjM2-Grammar.pdf -------------------------------------------------------------------------------- /Pesquisa/ToyPascal/LLVM_reference/add.txt: -------------------------------------------------------------------------------- 1 | C 2 | int add(int b,int c){ 3 | int a = c; 4 | return (a + b) ; 5 | 6 | } 7 | LLVM 8 | ; ModuleID = '/tmp/webcompile/_22499_0.bc' 9 | target datalayout = "e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:32:64-f32:32:32-f64:32:64-v64:64:64-v128:128:128-a0:0:64-s0:0:64-f80:32:32" 10 | target triple = "i686-pc-linux-gnu" 11 | 12 | define i32 @add(i32 %b, i32 %c) { 13 | entry: 14 | %tmp4 = add i32 %c, %b ; [#uses=1] 15 | ret i32 %tmp4 16 | } 17 | -------------------------------------------------------------------------------- /Pesquisa/ToyPascal/LLVM_reference/for.txt: -------------------------------------------------------------------------------- 1 | C 2 | int printoq() { 3 | int i = 0; 4 | for (i=0;i<52;i++){ 5 | printf("%d\n", i); 6 | } 7 | return i; 8 | } 9 | 10 | entry: 11 | br label %bb 12 | 13 | bb: 14 | %i.014.0 = phi i32 [ 0, %entry ], [ %indvar.next, %bb ] ; [#uses=2] 15 | 16 | ;%indvar.next é o cara que está sendo adicionado, seria a terceiro argumento do for 17 | %indvar.next = add i32 %i.014.0, 1 18 | 19 | ;%exitcond = icmp , 20 | ; var2 seria a condição de parada e var1 é a variavel comparada 21 | %exitcond = icmp eq i32 %indvar.next, 52 22 | 23 | ;aqui se verifica se é verdadeiro, se exitcond é TRUE, se for vai pra bb10, senão bb 24 | br i1 %exitcond, label %bb10, label %bb 25 | 26 | bb10: 27 | 28 | 29 | 30 | -------------------------------------------------------------------------------- /Pesquisa/ToyPascal/LLVM_reference/if.txt: -------------------------------------------------------------------------------- 1 | if: 2 | %evaluating = icmp eq i1 1, 1 3 | %tmp1 = icmp eq i1 %evaluating, 1 4 | br i1 %tmp1, label %cond_true, label %cond_false 5 | cond_true: 6 | 7 | cond_false: 8 | -------------------------------------------------------------------------------- /Pesquisa/ToyPascal/LLVM_reference/if_while.txt: -------------------------------------------------------------------------------- 1 | int main(void) { 2 | int i = 0; 3 | while( i< 32 ){ 4 | if(i == 15){ 5 | i++; 6 | } else { 7 | i = i + 3; 8 | } 9 | } 10 | return i; 11 | } 12 | 13 | 14 | Código em LLVM 15 | ; ModuleID = '/tmp/webcompile/_3741_0.bc' 16 | target datalayout = "e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:32:64-f32:32:32-f64:32:64-v64:64:64-v128:128:128-a0:0:64-s0:0:64-f80:32:32" 17 | target triple = "i686-pc-linux-gnu" 18 | 19 | define i32 @main() { 20 | entry: 21 | br label %bb 22 | 23 | bb: ; preds = %cond_false, %cond_true, %entry 24 | %i.017.0 = phi i32 [ 0, %entry ], [ %tmp5, %cond_true ], [ %tmp7, %cond_false ] ; [#uses=3] 25 | %tmp2 = icmp eq i32 %i.017.0, 15 ; [#uses=1] 26 | br i1 %tmp2, label %cond_true, label %cond_false 27 | 28 | cond_true: ; preds = %bb 29 | %tmp5 = add i32 %i.017.0, 1 ; [#uses=3] 30 | %tmp1025 = icmp slt i32 %tmp5, 32 ; [#uses=1] 31 | br i1 %tmp1025, label %bb, label %bb13 32 | 33 | cond_false: ; preds = %bb 34 | %tmp7 = add i32 %i.017.0, 3 ; [#uses=3] 35 | %tmp10 = icmp slt i32 %tmp7, 32 ; [#uses=1] 36 | br i1 %tmp10, label %bb, label %bb13 37 | 38 | bb13: ; preds = %cond_false, %cond_true 39 | %i.017.1 = phi i32 [ %tmp5, %cond_true ], [ %tmp7, %cond_false ] ; [#uses=1] 40 | ret i32 %i.017.1 41 | } 42 | 43 | -------------------------------------------------------------------------------- /Pesquisa/ToyPascal/LLVM_reference/putchar.txt: -------------------------------------------------------------------------------- 1 | C 2 | extern void putchar(unsigned char); 3 | 4 | int main(void) { 5 | putchar('a'); 6 | } 7 | 8 | LLVM 9 | //putchar 10 | ; ModuleID = '/tmp/webcompile/_2757_0.bc' 11 | target datalayout = "e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:32:64-f32:32:32-f64:32:64-v64:64:64-v128:128:128-a0:0:64-s0:0:64-f80:32:32" 12 | target triple = "i686-pc-linux-gnu" 13 | 14 | define i32 @main() { 15 | entry: 16 | tail call void @putchar( i8 97 zeroext ) 17 | ret i32 undef 18 | } 19 | 20 | declare void @putchar(i8 zeroext ) 21 | 22 | 23 | -------------------------------------------------------------------------------- /Pesquisa/ToyPascal/LLVM_reference/sub.txt: -------------------------------------------------------------------------------- 1 | C 2 | int add(int b,int c){ 3 | 4 | return (c - b) ; 5 | 6 | } 7 | LLVM 8 | ; ModuleID = '/tmp/webcompile/_23389_0.bc' 9 | target datalayout = "e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:32:64-f32:32:32-f64:32:64-v64:64:64-v128:128:128-a0:0:64-s0:0:64-f80:32:32" 10 | target triple = "i686-pc-linux-gnu" 11 | 12 | define i32 @add(i32 %b, i32 %c) { 13 | entry: 14 | %tmp3 = sub i32 %c, %b ; [#uses=1] 15 | ret i32 %tmp3 16 | } 17 | -------------------------------------------------------------------------------- /Pesquisa/ToyPascal/LLVM_reference/test.ll: -------------------------------------------------------------------------------- 1 | ; Generated with toypasc 2 | ; program @sample0 3 | 4 | ; Declare the string constants as a global constants... 5 | @.true_str = internal constant [5 x i8] c"true\00" 6 | @.false_str = internal constant [6 x i8] c"false\00" 7 | @.int_fmt = internal constant [3 x i8] c"%d\00" 8 | 9 | ; External declaration of functions 10 | declare i32 @puts(i8 *) 11 | declare i32 @putchar(i32) 12 | declare i32 @printf(i8*, ...) 13 | 14 | @x = global i32 0 15 | @a = global i1 0 16 | @b = global i1 0 17 | @c = global i8 0 18 | 19 | ; Definition of main function 20 | define i32 @main() 21 | { 22 | ; [Template] store i32 50, i32* @x, align 4 23 | ;store i32 2 + 3 * 5 + 9, i32* @x 24 | %tmp = add i32 13, 50 25 | 26 | call i32 (i8* noalias , ...)* bitcast (i32 (i8*, ...)* @printf to i32 (i8* noalias , ...)*)( i8* getelementptr ([3 x i8]* @.int_fmt, i32 0, i32 0) noalias , i32 %tmp ) 27 | 28 | call i32 @putchar( i32 10 ) 29 | 30 | ret i32 0 31 | } 32 | 33 | -------------------------------------------------------------------------------- /Pesquisa/ToyPascal/LLVM_reference/while.txt: -------------------------------------------------------------------------------- 1 | entry: 2 | %evaluating = icmp eq i1 1, 1 3 | br label %bb 4 | 5 | body: 6 | 7 | bb: 8 | %exitcond = icmp eq i1 %evaluating, 1 9 | br i1 %exitcond, label %body, label %exit 10 | exit: 11 | 12 | -------------------------------------------------------------------------------- /Pesquisa/ToyPascal/Makefile: -------------------------------------------------------------------------------- 1 | LEX=flex 2 | LEXFLAGS= 3 | YACC=bison 4 | YACCFLAGS=-v -t -d 5 | CC=gcc 6 | CFLAGS=-ggdb 7 | LIBS= 8 | PARSER=parser 9 | SCANNER=scanner 10 | OBJS=$(SCANNER).o $(PARSER).o symbol_table.o ast.o base.o typecheck_visitor.o simpleprinter_visitor.o graphprinter_visitor.o c_codegen_visitor.o llvm_codegen_visitor.o 11 | PROGRAM=toypasc 12 | 13 | all: $(OBJS) 14 | $(CC) $(LIBS) $(OBJS) -o $(PROGRAM) 15 | 16 | symbol_table.o: symbol_table.c symbol_table.h 17 | $(CC) $(CFLAGS) symbol_table.c -c 18 | 19 | base.o: base.c base.h 20 | $(CC) $(CFLAGS) base.c -c 21 | 22 | ast.o: ast.c ast.h 23 | $(CC) $(CFLAGS) ast.c -c 24 | 25 | typecheck_visitor.o: typecheck_visitor.c typecheck_visitor.h 26 | $(CC) $(CFLAGS) typecheck_visitor.c -c 27 | 28 | graphprinter_visitor.o: graphprinter_visitor.c graphprinter_visitor.h 29 | $(CC) $(CFLAGS) graphprinter_visitor.c -c 30 | 31 | simpleprinter_visitor.o: simpleprinter_visitor.c simpleprinter_visitor.h 32 | $(CC) $(CFLAGS) simpleprinter_visitor.c -c 33 | 34 | llvm_codegen_visitor.o: llvm_codegen_visitor.c llvm_codegen_visitor.h 35 | $(CC) $(CFLAGS) llvm_codegen_visitor.c -c 36 | 37 | c_codegen_visitor.o: c_codegen_visitor.c c_codegen_visitor.h 38 | $(CC) $(CFLAGS) c_codegen_visitor.c -c 39 | 40 | $(PARSER).o: $(PARSER).c $(PARSER).h 41 | $(CC) $(CFLAGS) $(PARSER).c -c 42 | 43 | $(SCANNER).o: $(SCANNER).c $(PARSER).h 44 | $(CC) $(CFLAGS) $(SCANNER).c -c 45 | 46 | $(SCANNER).c: $(SCANNER).l 47 | $(LEX) $(LEXFLAGS) -o$(SCANNER).c $(SCANNER).l 48 | 49 | $(PARSER).h: $(PARSER).y 50 | $(YACC) $(YACCFLAGS) $(PARSER).y -o $(PARSER).c 51 | 52 | clean: 53 | rm -rf $(SCANNER).c $(PARSER).c $(PARSER).h *.o $(PROGRAM) 54 | -------------------------------------------------------------------------------- /Pesquisa/ToyPascal/ast.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include "ast.h" 5 | #include "typecheck_visitor.h" 6 | 7 | struct AstNode * 8 | ast_node_new(const char* name, int kind, int type, 9 | int linenum, Symbol *symbol) 10 | { 11 | int i; 12 | struct AstNode *node; 13 | 14 | node = (struct AstNode *) malloc (sizeof(struct AstNode)); 15 | 16 | if (name != NULL){ 17 | node->name = strdup(name); 18 | } else 19 | node->name = NULL; 20 | 21 | node->kind = kind; 22 | node->type = type; 23 | node->linenum = linenum; 24 | node->child_counter = 0; 25 | node->symbol = symbol; 26 | node->parent = NULL; 27 | node->children = NULL; 28 | node->sibling = NULL; 29 | 30 | return node; 31 | } 32 | 33 | void 34 | ast_node_destroy(struct AstNode *self) 35 | { 36 | if (self != NULL) { 37 | ast_node_destroy(self->children); 38 | ast_node_destroy(self->sibling); 39 | free(self); 40 | } 41 | } 42 | 43 | Value 44 | ast_node_get_value(struct AstNode *self) 45 | { 46 | if (self->kind == IDENTIFIER) 47 | return self->symbol->value; 48 | 49 | return self->value; 50 | } 51 | 52 | int 53 | ast_node_get_value_as_int(struct AstNode *self) 54 | { 55 | if (self->kind == IDENTIFIER) 56 | return self->symbol->value.integer; 57 | 58 | return self->value.integer; 59 | } 60 | 61 | int 62 | ast_node_get_child_counter(struct AstNode *self) 63 | { 64 | return self->child_counter++; 65 | } 66 | 67 | bool 68 | ast_node_check_errors(struct AstNode *self) 69 | { 70 | struct AstNode *child; 71 | 72 | if (self == NULL || self->type == ERROR) 73 | return TRUE; 74 | 75 | for (child = self->children; child != NULL; child = child->sibling) { 76 | if (ast_node_check_errors(child) == TRUE) 77 | return TRUE; 78 | } 79 | 80 | return FALSE; 81 | } 82 | 83 | void 84 | ast_node_add_child(struct AstNode *self, struct AstNode *child) 85 | { 86 | struct AstNode *temp; 87 | 88 | if (child == NULL) 89 | return; 90 | 91 | if (self->children == NULL) { 92 | child->parent = self; 93 | self->children = child; 94 | } else { 95 | ast_node_add_sibling(self->children, child); 96 | } 97 | for (temp = child; temp != NULL; temp = temp->sibling) 98 | temp->parent = self; 99 | } 100 | 101 | void 102 | ast_node_add_sibling(struct AstNode *self, struct AstNode *sibling) 103 | { 104 | struct AstNode *temp; 105 | 106 | if (sibling == NULL) 107 | return; 108 | 109 | if (self->sibling == NULL) { 110 | self->sibling = sibling; 111 | } else { 112 | for (temp = self->sibling; temp->sibling != NULL; temp = temp->sibling) 113 | ; 114 | temp->sibling = sibling; 115 | } 116 | } 117 | 118 | void 119 | ast_node_accept(struct AstNode *self, Visitor *visitor) 120 | { 121 | VisitFunc visit; 122 | 123 | if (self == NULL) 124 | return; 125 | 126 | self->child_counter = 1; 127 | 128 | switch (self->kind) { 129 | case PROGRAM: 130 | visit = visitor->visit_program; 131 | break; 132 | case PROGRAM_DECL: 133 | visit = visitor->visit_programdecl; 134 | break; 135 | case VARDECL_LIST: 136 | visit = visitor->visit_vardecl_list; 137 | break; 138 | case VARDECL: 139 | visit = visitor->visit_vardecl; 140 | break; 141 | case IDENT_LIST: 142 | visit = visitor->visit_identifier_list; 143 | break; 144 | case PROCFUNC_LIST: 145 | visit = visitor->visit_procfunc_list; 146 | break; 147 | case PROCEDURE: 148 | visit = visitor->visit_procedure; 149 | break; 150 | case FUNCTION: 151 | visit = visitor->visit_function; 152 | break; 153 | case PARAM_LIST: 154 | visit = visitor->visit_param_list; 155 | break; 156 | case PARAMETER: 157 | visit = visitor->visit_parameter; 158 | break; 159 | case STATEMENT_LIST: 160 | visit = visitor->visit_statement_list; 161 | break; 162 | case PRINTINT_STMT: 163 | visit = visitor->visit_printint_stmt; 164 | break; 165 | case PRINTCHAR_STMT: 166 | visit = visitor->visit_printchar_stmt; 167 | break; 168 | case PRINTBOOL_STMT: 169 | visit = visitor->visit_printbool_stmt; 170 | break; 171 | case PRINTLINE_STMT: 172 | visit = visitor->visit_printline_stmt; 173 | break; 174 | case ASSIGNMENT_STMT: 175 | visit = visitor->visit_assignment_stmt; 176 | break; 177 | case IF_STMT: 178 | visit = visitor->visit_if_stmt; 179 | break; 180 | case WHILE_STMT: 181 | visit = visitor->visit_while_stmt; 182 | break; 183 | case FOR_STMT: 184 | visit = visitor->visit_for_stmt; 185 | break; 186 | case REL_EXPR: 187 | visit = visitor->visit_rel_expr; 188 | break; 189 | case ADD_EXPR: 190 | visit = visitor->visit_add_expr; 191 | break; 192 | case MUL_EXPR: 193 | visit = visitor->visit_mul_expr; 194 | break; 195 | case NOTFACTOR: 196 | visit = visitor->visit_notfactor; 197 | break; 198 | case CALL: 199 | visit = visitor->visit_call; 200 | break; 201 | case CALLPARAM_LIST: 202 | visit = visitor->visit_callparam_list; 203 | break; 204 | case CALLPARAM: 205 | visit = visitor->visit_callparam; 206 | break; 207 | case IDENTIFIER: 208 | visit = visitor->visit_identifier; 209 | break; 210 | case INT_LITERAL: 211 | case BOOL_LITERAL: 212 | case CHAR_LITERAL: 213 | visit = visitor->visit_literal; 214 | break; 215 | case T_PLUS: 216 | case T_MINUS: 217 | case T_OR: 218 | visit = visitor->visit_add_op; 219 | break; 220 | case T_STAR: 221 | case T_SLASH: 222 | case T_AND: 223 | visit = visitor->visit_mul_op; 224 | break; 225 | case T_EQUAL: 226 | case T_NOTEQUAL: 227 | case T_LESSER: 228 | case T_GREATER: 229 | case T_LESSEREQUAL: 230 | case T_GREATEREQUAL: 231 | visit = visitor->visit_rel_op; 232 | break; 233 | case T_NOT: 234 | visit = visitor->visit_not_op; 235 | break; 236 | default: 237 | visit = NULL; 238 | } 239 | 240 | if (visit != NULL) 241 | visit(visitor, self); 242 | } 243 | 244 | void 245 | ast_node_accept_children(struct AstNode *self, Visitor *visitor) 246 | { 247 | struct AstNode *temp; 248 | for (temp = self; temp != NULL; temp = temp->sibling) 249 | ast_node_accept(temp, visitor); 250 | } 251 | 252 | -------------------------------------------------------------------------------- /Pesquisa/ToyPascal/ast.h: -------------------------------------------------------------------------------- 1 | #ifndef AST_H 2 | #define AST_H 3 | 4 | #include "base.h" 5 | #include "parser.h" 6 | #include "symbol_table.h" 7 | 8 | struct AstNode { 9 | char *name; 10 | int kind; 11 | Type type; 12 | Value value; 13 | Symbol *symbol; 14 | int linenum; 15 | int child_counter; 16 | struct AstNode* parent; 17 | struct AstNode* children; 18 | struct AstNode* sibling; 19 | }; 20 | 21 | typedef struct _Visitor { 22 | void (*visit_program) (struct _Visitor *, struct AstNode *); 23 | void (*visit_programdecl) (struct _Visitor *, struct AstNode *); 24 | void (*visit_vardecl_list) (struct _Visitor *, struct AstNode *); 25 | void (*visit_vardecl) (struct _Visitor *, struct AstNode *); 26 | void (*visit_identifier_list) (struct _Visitor *, struct AstNode *); 27 | void (*visit_identifier) (struct _Visitor *, struct AstNode *); 28 | void (*visit_procfunc_list) (struct _Visitor *, struct AstNode *); 29 | void (*visit_procedure) (struct _Visitor *, struct AstNode *); 30 | void (*visit_function) (struct _Visitor *, struct AstNode *); 31 | void (*visit_param_list) (struct _Visitor *, struct AstNode *); 32 | void (*visit_parameter) (struct _Visitor *, struct AstNode *); 33 | void (*visit_statement_list) (struct _Visitor *, struct AstNode *); 34 | void (*visit_printint_stmt) (struct _Visitor *, struct AstNode *); 35 | void (*visit_printchar_stmt) (struct _Visitor *, struct AstNode *); 36 | void (*visit_printbool_stmt) (struct _Visitor *, struct AstNode *); 37 | void (*visit_printline_stmt) (struct _Visitor *, struct AstNode *); 38 | void (*visit_assignment_stmt) (struct _Visitor *, struct AstNode *); 39 | void (*visit_if_stmt) (struct _Visitor *, struct AstNode *); 40 | void (*visit_while_stmt) (struct _Visitor *, struct AstNode *); 41 | void (*visit_for_stmt) (struct _Visitor *, struct AstNode *); 42 | void (*visit_rel_expr) (struct _Visitor *, struct AstNode *); 43 | void (*visit_add_expr) (struct _Visitor *, struct AstNode *); 44 | void (*visit_mul_expr) (struct _Visitor *, struct AstNode *); 45 | void (*visit_notfactor) (struct _Visitor *, struct AstNode *); 46 | void (*visit_call) (struct _Visitor *, struct AstNode *); 47 | void (*visit_callparam_list) (struct _Visitor *, struct AstNode *); 48 | void (*visit_callparam) (struct _Visitor *, struct AstNode *); 49 | void (*visit_literal) (struct _Visitor *, struct AstNode *); 50 | void (*visit_add_op) (struct _Visitor *, struct AstNode *); 51 | void (*visit_mul_op) (struct _Visitor *, struct AstNode *); 52 | void (*visit_rel_op) (struct _Visitor *, struct AstNode *); 53 | void (*visit_not_op) (struct _Visitor *, struct AstNode *); 54 | } Visitor; 55 | 56 | typedef void (*VisitFunc)(struct _Visitor *, struct AstNode *); 57 | 58 | struct AstNode *ast_node_new(const char *name, int kind, int type, 59 | int linenum, Symbol *symbol); 60 | void ast_node_destroy(struct AstNode *); 61 | 62 | Value ast_node_get_value(struct AstNode *); 63 | int ast_node_get_value_as_int(struct AstNode *); 64 | int ast_node_get_child_counter(struct AstNode *); 65 | bool ast_node_check_errors(struct AstNode *); 66 | void ast_node_add_child(struct AstNode *, struct AstNode *); 67 | void ast_node_add_sibling(struct AstNode *, struct AstNode *); 68 | void ast_node_accept(struct AstNode *, Visitor *); 69 | void ast_node_accept_children(struct AstNode *, Visitor *); 70 | 71 | #endif // AST_H 72 | -------------------------------------------------------------------------------- /Pesquisa/ToyPascal/base.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include "base.h" 5 | 6 | Type 7 | type_get_from_lexeme(const char *lexeme) 8 | { 9 | if (!strcasecmp (lexeme, "Integer")) 10 | return INTEGER; 11 | else if (!strcasecmp (lexeme, "Boolean")) 12 | return BOOLEAN; 13 | else if (!strcasecmp (lexeme, "Char")) 14 | return CHAR; 15 | else 16 | return VOID; 17 | } 18 | 19 | char * 20 | type_get_lexeme(Type type) 21 | { 22 | switch (type) { 23 | case VOID: 24 | return "void"; 25 | case INTEGER: 26 | return "Integer"; 27 | case BOOLEAN: 28 | return "Boolean"; 29 | case CHAR: 30 | return "Char"; 31 | case ERROR: 32 | return "Error"; 33 | default: 34 | return ""; 35 | } 36 | } 37 | 38 | void 39 | value_print(FILE *file, Value *value, Type type) 40 | { 41 | if (type == INTEGER) { 42 | fprintf(file, "%d", value->integer); 43 | } else if (type == BOOLEAN) { 44 | fprintf(file, "%s", value->boolean ? "true" : "false"); 45 | } else if (type == CHAR) { 46 | fprintf(file, "'%c'", value->character); 47 | } 48 | } 49 | 50 | void 51 | value_get(Value *value, Type type, void *val) 52 | { 53 | if (value == NULL) { 54 | fprintf(stderr, "base.c: value_get: value == NULL\n"); 55 | exit(1); 56 | } 57 | 58 | if (type == INTEGER) { 59 | *((int *) val) = value->integer; 60 | } else if (type == BOOLEAN) { 61 | *((bool *) val) = value->boolean; 62 | } else if (type == CHAR) { 63 | *((char *) val) = value->character; 64 | } else { 65 | fprintf(stderr, "base.c: value_get: unknow type\n"); 66 | exit(1); 67 | } 68 | } 69 | 70 | void 71 | value_set(Value *value, Type type, void *val) 72 | { 73 | if (value == NULL) { 74 | fprintf(stderr, "base.c: value_set: value == NULL\n"); 75 | exit(1); 76 | } 77 | 78 | if (type == VOID || val == NULL) { 79 | value->integer = 0; 80 | } else if (type == INTEGER) { 81 | value->integer = *((int *) val); 82 | } else if (type == BOOLEAN) { 83 | value->boolean = *((bool *) val); 84 | } else if (type == CHAR) { 85 | value->character = *((char *) val); 86 | } else { 87 | fprintf(stderr, "base.c: value_set: unknow type\n"); 88 | exit(1); 89 | } 90 | } 91 | 92 | void 93 | value_set_from_int(Value *value, int val) 94 | { 95 | value_set(value, INTEGER, VOID(val)); 96 | } 97 | 98 | void 99 | value_set_from_bool(Value *value, bool val) 100 | { 101 | value_set(value, BOOLEAN, VOID(val)); 102 | } 103 | 104 | void 105 | value_set_from_char(Value *value, char val) 106 | { 107 | value_set(value, CHAR, VOID(val)); 108 | } 109 | 110 | -------------------------------------------------------------------------------- /Pesquisa/ToyPascal/base.h: -------------------------------------------------------------------------------- 1 | #ifndef BASE_H 2 | #define BASE_H 3 | 4 | #define VOID(var) ((void *) &var) 5 | #define IS_LITERAL(k) (k == BOOL_LITERAL || \ 6 | k == CHAR_LITERAL || \ 7 | k == INT_LITERAL) 8 | 9 | typedef enum { 10 | FALSE = 0, 11 | TRUE 12 | } bool; 13 | 14 | typedef enum TypeEnum { 15 | ERROR = -1, 16 | VOID, 17 | INTEGER, 18 | BOOLEAN, 19 | CHAR 20 | } Type; 21 | 22 | typedef enum KindEnum { 23 | NONE_KIND = -1, 24 | PROGRAM, 25 | PROGRAM_DECL, 26 | VARDECL_LIST, 27 | VARDECL, 28 | IDENT_LIST, 29 | PROCFUNC_LIST, 30 | PROCEDURE, 31 | FUNCTION, 32 | PARAM_LIST, 33 | PARAMETER, 34 | STATEMENT_LIST, 35 | PRINTINT_STMT, 36 | PRINTCHAR_STMT, 37 | PRINTBOOL_STMT, 38 | PRINTLINE_STMT, 39 | ASSIGNMENT_STMT, 40 | IF_STMT, 41 | WHILE_STMT, 42 | FOR_STMT, 43 | REL_EXPR, 44 | ADD_EXPR, 45 | MUL_EXPR, 46 | NOTFACTOR, 47 | CALL, 48 | CALLPARAM_LIST, 49 | CALLPARAM, 50 | //IDENTIFIER defined as token 51 | //INT_LITERAL, BOOL_LITERAL, CHAR_LITERAL defined as tokens 52 | } Kind; 53 | 54 | typedef union { 55 | int integer; 56 | bool boolean; 57 | char character; 58 | } Value; 59 | 60 | char *type_get_lexeme(Type type); 61 | Type type_get_from_lexeme(const char *lexeme); 62 | 63 | void value_get(Value *value, Type type, void *val); 64 | void value_set(Value *value, Type type, void *val); 65 | 66 | void value_set_from_int(Value *value, int val); 67 | void value_set_from_bool(Value *value, bool val); 68 | void value_set_from_char(Value *value, char val); 69 | 70 | void value_print(FILE *file, Value *value, Type type); 71 | 72 | #endif // BASE_H 73 | 74 | -------------------------------------------------------------------------------- /Pesquisa/ToyPascal/c_codegen_visitor.h: -------------------------------------------------------------------------------- 1 | #ifndef C_CODEGEN_VISITOR_H 2 | #define C_CODEGEN_VISITOR_H 3 | 4 | #include "ast.h" 5 | 6 | #define TAB " " 7 | 8 | Visitor *c_codegen_new(); 9 | 10 | void c_codegen_visit_program (struct _Visitor *, struct AstNode *); 11 | void c_codegen_visit_programdecl (struct _Visitor *, struct AstNode *); 12 | void c_codegen_visit_procfunc_list (struct _Visitor *, struct AstNode *); 13 | void c_codegen_visit_procfunc (struct _Visitor *, struct AstNode *); 14 | void c_codegen_visit_vardecl_list (struct _Visitor *, struct AstNode *); 15 | void c_codegen_visit_vardecl (struct _Visitor *, struct AstNode *); 16 | void c_codegen_visit_identifier_list (struct _Visitor *, struct AstNode *); 17 | void c_codegen_visit_param_list (struct _Visitor *, struct AstNode *); 18 | void c_codegen_visit_parameter (struct _Visitor *, struct AstNode *); 19 | void c_codegen_visit_statement_list(struct _Visitor *, struct AstNode *); 20 | void c_codegen_visit_printint_stmt (struct _Visitor *, struct AstNode *); 21 | void c_codegen_visit_printchar_stmt (struct _Visitor *, struct AstNode *); 22 | void c_codegen_visit_printbool_stmt (struct _Visitor *, struct AstNode *); 23 | void c_codegen_visit_printline_stmt (struct _Visitor *, struct AstNode *); 24 | void c_codegen_visit_assignment_stmt (struct _Visitor *, struct AstNode *); 25 | void c_codegen_visit_if_stmt (struct _Visitor *, struct AstNode *); 26 | void c_codegen_visit_while_stmt (struct _Visitor *, struct AstNode *); 27 | void c_codegen_visit_for_stmt (struct _Visitor *, struct AstNode *); 28 | void c_codegen_visit_binary_expr (struct _Visitor *, struct AstNode *); 29 | void c_codegen_visit_notfactor (struct _Visitor *, struct AstNode *); 30 | void c_codegen_visit_call (struct _Visitor *, struct AstNode *); 31 | void c_codegen_visit_callparam_list (struct _Visitor *, struct AstNode *); 32 | void c_codegen_visit_identifier (struct _Visitor *, struct AstNode *); 33 | void c_codegen_visit_literal (struct _Visitor *, struct AstNode *); 34 | void c_codegen_visit_binary_op (struct _Visitor *, struct AstNode *); 35 | void c_codegen_visit_not_op (struct _Visitor *, struct AstNode *); 36 | 37 | #endif // C_CODEGEN_VISITOR_H 38 | -------------------------------------------------------------------------------- /Pesquisa/ToyPascal/graphprinter_visitor.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include "graphprinter_visitor.h" 5 | 6 | static void _print_arrow(struct AstNode *node); 7 | static void _print_symbol_table(struct AstNode *node); 8 | static void _print_symbols(Symbol *symbol); 9 | 10 | Visitor * 11 | graphprinter_new() 12 | { 13 | Visitor *visitor = (Visitor *) malloc (sizeof(Visitor)); 14 | 15 | visitor->visit_program = &graphprinter_visit_program; 16 | visitor->visit_programdecl = &graphprinter_visit_programdecl; 17 | visitor->visit_vardecl_list = &graphprinter_visit_vardecl_list; 18 | visitor->visit_vardecl = &graphprinter_visit_simplenode; 19 | visitor->visit_identifier_list = &graphprinter_visit_identifier_list; 20 | visitor->visit_procfunc_list = &graphprinter_visit_procfunc_list; 21 | visitor->visit_procedure = &graphprinter_visit_procfunc; 22 | visitor->visit_function = &graphprinter_visit_procfunc; 23 | visitor->visit_param_list = &graphprinter_visit_param_list; 24 | visitor->visit_parameter = &graphprinter_visit_parameter; 25 | visitor->visit_statement_list = &graphprinter_visit_statement_list; 26 | visitor->visit_printint_stmt = &graphprinter_visit_simplenode; 27 | visitor->visit_printchar_stmt = &graphprinter_visit_simplenode; 28 | visitor->visit_printbool_stmt = &graphprinter_visit_simplenode; 29 | visitor->visit_printline_stmt = &graphprinter_visit_simplenode; 30 | visitor->visit_assignment_stmt = &graphprinter_visit_simplenode; 31 | visitor->visit_if_stmt = &graphprinter_visit_simplenode; 32 | visitor->visit_while_stmt = &graphprinter_visit_simplenode; 33 | visitor->visit_for_stmt = &graphprinter_visit_simplenode; 34 | visitor->visit_rel_expr = &graphprinter_visit_binary_expr; 35 | visitor->visit_add_expr = &graphprinter_visit_binary_expr; 36 | visitor->visit_mul_expr = &graphprinter_visit_binary_expr; 37 | visitor->visit_notfactor = &graphprinter_visit_simplenode; 38 | visitor->visit_call = &graphprinter_visit_call; 39 | visitor->visit_callparam_list = &graphprinter_visit_callparam_list; 40 | visitor->visit_callparam = &graphprinter_visit_callparam; 41 | visitor->visit_identifier = &graphprinter_visit_identifier; 42 | visitor->visit_literal = &graphprinter_visit_literal; 43 | visitor->visit_add_op = NULL; 44 | visitor->visit_mul_op = NULL; 45 | visitor->visit_rel_op = NULL; 46 | visitor->visit_not_op = NULL; 47 | 48 | return visitor; 49 | } 50 | 51 | void 52 | graphprinter_visit_program(struct _Visitor *visitor, struct AstNode *node) 53 | { 54 | printf("/* toypasc AST graph. */\n"); 55 | printf("digraph {\n"); 56 | 57 | printf("\tremincross=true;\n"); 58 | printf("\tordering=out;\n"); 59 | printf("\tcompound=true;\n"); 60 | printf("\tranksep=1.0;\n"); 61 | printf("\tnode [fontsize=11,fontname=Courier];\n"); 62 | printf("\tedge [color="COLOR_EDGE_GROUP"];\n\n"); 63 | 64 | printf("\tnode_%x [label=\"%s\",fontsize=16,fontname=Courier,", 65 | node, node->name); 66 | printf("style=filled,color=black,fillcolor="COLOR_FILL_GLOBAL"];\n"); 67 | 68 | _print_symbol_table(node); 69 | 70 | ast_node_accept_children(node->children, visitor); 71 | 72 | printf("}\n"); 73 | } 74 | 75 | void 76 | graphprinter_visit_simplenode (struct _Visitor *visitor, struct AstNode *node) 77 | { 78 | _print_arrow(node); 79 | printf("\tnode_%x [label=\"%s\\n[line: %d]\",style=filled,", 80 | node, node->name, node->linenum); 81 | printf("fillcolor="COLOR_FILL_COMMON",color=%s];\n", 82 | (node->type == ERROR) ? COLOR_EDGE_ERROR : COLOR_FILL_COMMON); 83 | ast_node_accept_children(node->children, visitor); 84 | } 85 | 86 | void 87 | graphprinter_visit_programdecl(struct _Visitor *visitor, struct AstNode *node) 88 | { 89 | _print_arrow(node); 90 | printf("\tnode_%x [label=\"%s\\n[line: %d]\",style=filled,", 91 | node, node->name, node->linenum); 92 | printf("color="COLOR_EDGE_GROUP",fillcolor="COLOR_FILL_COMMON"];\n"); 93 | ast_node_accept(node->children, visitor); 94 | printf("\tnode_%x -> symbol_%x [color=lightgray];\n", node->children, node->children->symbol); 95 | } 96 | 97 | void 98 | graphprinter_visit_vardecl_list (struct _Visitor *visitor, struct AstNode *node) 99 | { 100 | _print_arrow(node); 101 | printf("\tnode_%x [label=\"%s\",style=filled,", node, node->name); 102 | printf("color="COLOR_EDGE_GROUP",fillcolor="COLOR_FILL_COMMON"];\n"); 103 | printf("\nsubgraph cluster_%x {\n\tstyle=dotted;\n", node); 104 | ast_node_accept_children(node->children, visitor); 105 | printf("}\n\n"); 106 | } 107 | 108 | void 109 | graphprinter_visit_identifier_list (struct _Visitor *visitor, struct AstNode *node) 110 | { 111 | _print_arrow(node); 112 | printf("\tnode_%x [label=\"%s\",style=filled,", node, node->name); 113 | printf("color="COLOR_EDGE_GROUP",fillcolor="COLOR_FILL_COMMON"];\n"); 114 | printf("\nsubgraph cluster_%x {\n\tstyle=dotted;\n", node); 115 | ast_node_accept_children(node->children, visitor); 116 | printf("}\n\n"); 117 | } 118 | 119 | void 120 | graphprinter_visit_procfunc_list (struct _Visitor *visitor, struct AstNode *node) 121 | { 122 | _print_arrow(node); 123 | printf("\tnode_%x [label=\"%s\",style=filled,", node, node->name); 124 | printf("color="COLOR_EDGE_GROUP",fillcolor="COLOR_FILL_COMMON"];\n"); 125 | ast_node_accept_children(node->children, visitor); 126 | } 127 | 128 | void 129 | graphprinter_visit_procfunc (struct _Visitor *visitor, struct AstNode *node) 130 | { 131 | _print_arrow(node); 132 | printf("\tnode_%x [label=\"%s\\n<%s>\\n[line: %d]\",style=filled,", 133 | node, node->name, type_get_lexeme(node->type), node->linenum); 134 | printf("color=blue,fillcolor="COLOR_EDGE_FUNCT"];\n"); 135 | printf("\nsubgraph cluster_%x {\n\tstyle=dotted;\n", node); 136 | 137 | _print_symbol_table(node); 138 | ast_node_accept_children(node->children, visitor); 139 | printf("}\n\n"); 140 | } 141 | 142 | void 143 | graphprinter_visit_param_list (struct _Visitor *visitor, struct AstNode *node) 144 | { 145 | _print_arrow(node); 146 | printf("\tnode_%x [label=\"%s\",style=filled,", node, node->name); 147 | printf("color="COLOR_EDGE_GROUP",fillcolor="COLOR_FILL_COMMON"];\n"); 148 | printf("\nsubgraph cluster_%x {\n\tstyle=dotted;\n", node); 149 | ast_node_accept_children(node->children, visitor); 150 | printf("}\n\n"); 151 | } 152 | 153 | void 154 | graphprinter_visit_parameter (struct _Visitor *visitor, struct AstNode *node) 155 | { 156 | _print_arrow(node); 157 | printf("\tnode_%x [label=\"%s\",style=filled,", node, node->name); 158 | printf("fillcolor="COLOR_FILL_COMMON",color=%s];\n", 159 | (node->type == ERROR) ? COLOR_EDGE_ERROR : COLOR_FILL_COMMON); 160 | ast_node_accept_children(node->children, visitor); 161 | } 162 | 163 | void 164 | graphprinter_visit_statement_list (struct _Visitor *visitor, struct AstNode *node) 165 | { 166 | _print_arrow(node); 167 | printf("\tnode_%x [label=\"%s\",style=filled,", node, node->name); 168 | printf("color="COLOR_EDGE_GROUP",fillcolor="COLOR_FILL_COMMON"];\n"); 169 | printf("\nsubgraph cluster_%x {\n\tstyle=dotted;\n", node); 170 | ast_node_accept_children(node->children, visitor); 171 | printf("}\n\n"); 172 | } 173 | 174 | void 175 | graphprinter_visit_binary_expr (struct _Visitor *visitor, struct AstNode *node) 176 | { 177 | _print_arrow(node); 178 | printf("\tnode_%x [label=\"%s\\n'%s'\",style=filled,", 179 | node, node->name, node->children->sibling->name); 180 | printf("fillcolor="COLOR_FILL_COMMON",color=%s];\n", 181 | (node->type == ERROR) ? COLOR_EDGE_ERROR : COLOR_FILL_COMMON); 182 | ast_node_accept_children(node->children, visitor); 183 | } 184 | 185 | void 186 | graphprinter_visit_call (struct _Visitor *visitor, struct AstNode *node) 187 | { 188 | struct AstNode *ident = node->children; 189 | struct AstNode *plist = ident->sibling; 190 | 191 | _print_arrow(node); 192 | printf("\tnode_%x [label=\"%s\\n[line: %d]\",style=filled,", 193 | node, node->name, node->linenum); 194 | printf("fillcolor="COLOR_FILL_COMMON",color=%s];\n", 195 | (node->type == ERROR) ? COLOR_EDGE_ERROR : COLOR_FILL_COMMON); 196 | printf("\nsubgraph cluster_%x {\n\tstyle=dotted;\n", node); 197 | ast_node_accept(ident, visitor); 198 | ast_node_accept(plist, visitor); 199 | printf("}\n\n"); 200 | } 201 | 202 | void 203 | graphprinter_visit_callparam_list (struct _Visitor *visitor, struct AstNode *node) 204 | { 205 | int i; 206 | 207 | _print_arrow(node); 208 | printf("\tnode_%x [label=\"%s\\n<", node, node->name); 209 | 210 | for (i = 0; i < node->symbol->params; i++) { 211 | printf("%s", type_get_lexeme(node->symbol->param_types[i])); 212 | if (i + 1 < node->symbol->params) 213 | printf(", "); 214 | } 215 | 216 | 217 | printf(">\",style=filled,fillcolor="COLOR_FILL_COMMON",color=%s];\n", 218 | (node->type == ERROR) ? COLOR_EDGE_ERROR : COLOR_EDGE_GROUP); 219 | 220 | ast_node_accept_children(node->children, visitor); 221 | } 222 | 223 | void 224 | graphprinter_visit_callparam (struct _Visitor *visitor, struct AstNode *node) 225 | { 226 | _print_arrow(node); 227 | printf("\tnode_%x [label=\"%s\\n<%s>\",style=filled,", 228 | node, node->name, type_get_lexeme(node->type)); 229 | printf("fillcolor="COLOR_FILL_COMMON",color=%s];\n", 230 | (node->type == ERROR) ? COLOR_EDGE_ERROR : COLOR_FILL_COMMON); 231 | ast_node_accept_children(node->children, visitor); 232 | } 233 | 234 | void 235 | graphprinter_visit_identifier (struct _Visitor *visitor, struct AstNode *node) 236 | { 237 | _print_arrow(node); 238 | 239 | printf("\tnode_%x [label=\"", node); 240 | 241 | if (node->symbol->decl_linenum == 0) 242 | printf("UNDECLARED\\n"); 243 | 244 | printf("%s\\n'%s'\\n<%s>\",style=filled,color=", 245 | node->name, node->symbol->name, type_get_lexeme(node->type)); 246 | 247 | if (node->symbol->decl_linenum == 0) 248 | printf(COLOR_EDGE_ERROR); 249 | else if (node->symbol->is_global) 250 | printf(COLOR_FILL_GLOBAL); 251 | else 252 | printf(COLOR_FILL_LOCAL); 253 | 254 | printf(",fillcolor="); 255 | 256 | if (node->symbol->is_global) 257 | printf(COLOR_FILL_GLOBAL); 258 | else 259 | printf(COLOR_FILL_LOCAL); 260 | 261 | printf("];\n"); 262 | } 263 | 264 | void 265 | graphprinter_visit_literal (struct _Visitor *visitor, struct AstNode *node) 266 | { 267 | printf("\tnode_%x -> literal_%x;\n", node->parent, node); 268 | printf("\tliteral_%x [label=\"", node); 269 | value_print(stdout, &node->value, node->type); 270 | printf("\\n<%s>\",style=filled,color="COLOR_FILL_LITERAL"];\n", 271 | node->name, type_get_lexeme(node->type)); 272 | ast_node_accept_children(node->children, visitor); 273 | } 274 | 275 | // Helper functions ---------------------------------------------------------- 276 | 277 | static void 278 | _print_arrow(struct AstNode *node) 279 | { 280 | printf("\tnode_%x -> node_%x [label=\"%d\",", 281 | node->parent, node, ast_node_get_child_counter(node->parent)); 282 | printf("fontsize=11,fontname=Courier];\n"); 283 | } 284 | 285 | static void 286 | _print_symbol_table(struct AstNode *node) 287 | { 288 | if (node->symbol->next == NULL) 289 | return; 290 | 291 | printf("\tnode_%x -> symbol_%x [lhead=cluster_symtab_%x,color=", 292 | node, node->symbol->next, node); 293 | if (node->parent == NULL) 294 | printf("black];\n"); 295 | else 296 | printf("blue];\n"); 297 | 298 | printf("\n\tsubgraph cluster_symtab_%x {\n", node); 299 | 300 | if (node->parent == NULL) 301 | printf("\t\tcolor=black;\n"); 302 | else 303 | printf("\t\tcolor=blue;\n"); 304 | 305 | printf("\t\tstyle=filled;\n\t\tfillcolor="COLOR_FILL_GLOBAL";\n\t\tfontname=Courier;\n"); 306 | printf("\t\tnode [style=filled,color=white,fillcolor="COLOR_FILL_SYMBOL"];\n"); 307 | 308 | _print_symbols(node->symbol->next); 309 | 310 | printf("\t}\n\n"); 311 | } 312 | 313 | static void 314 | _print_symbols(Symbol *symbol) 315 | { 316 | if (symbol == NULL) 317 | return; 318 | 319 | if (symbol->name != NULL) { 320 | printf("\t\tsymbol_%x [shape=record,label=\"{", symbol); 321 | printf("Symbol|Address: 0x%x\\l|lexeme: %s\\l|", symbol, symbol->name); 322 | printf("type: %s\\l}\"", type_get_lexeme(symbol->type)); 323 | printf(",style=filled,color=white,fillcolor="COLOR_FILL_SYMBOL"];\n"); 324 | 325 | if (symbol->next != NULL) 326 | printf("\tsymbol_%x -> symbol_%x;\n", symbol, symbol->next); 327 | 328 | } 329 | 330 | _print_symbols(symbol->next); 331 | } 332 | 333 | -------------------------------------------------------------------------------- /Pesquisa/ToyPascal/graphprinter_visitor.h: -------------------------------------------------------------------------------- 1 | #ifndef GRAPHPRINTER_VISITOR_H 2 | #define GRAPHPRINTER_VISITOR_H 3 | 4 | #include "ast.h" 5 | 6 | #define COLOR_FILL_GLOBAL "\"#EEEEEE\"" 7 | #define COLOR_FILL_LOCAL "\"#CAE7FF\"" 8 | #define COLOR_FILL_COMMON "\"#EEFFEE\"" 9 | #define COLOR_FILL_LITERAL "\"#FFFFCC\"" 10 | #define COLOR_FILL_SYMBOL "\"#CCFF99\"" 11 | #define COLOR_FILL_ERROR "\"#FFEEEE\"" 12 | 13 | #define COLOR_EDGE_GROUP "\"#22DDAA\"" 14 | #define COLOR_EDGE_FUNCT "\"#EEEEFF\"" 15 | #define COLOR_EDGE_ERROR "\"#FF0000\"" 16 | 17 | Visitor *graphprinter_new(); 18 | 19 | void graphprinter_visit_program (struct _Visitor *, struct AstNode *); 20 | void graphprinter_visit_programdecl (struct _Visitor *, struct AstNode *); 21 | void graphprinter_visit_vardecl_list (struct _Visitor *, struct AstNode *); 22 | void graphprinter_visit_identifier_list (struct _Visitor *, struct AstNode *); 23 | void graphprinter_visit_procfunc_list (struct _Visitor *, struct AstNode *); 24 | void graphprinter_visit_procfunc (struct _Visitor *, struct AstNode *); 25 | void graphprinter_visit_param_list (struct _Visitor *, struct AstNode *); 26 | void graphprinter_visit_parameter (struct _Visitor *, struct AstNode *); 27 | void graphprinter_visit_statement_list (struct _Visitor *, struct AstNode *); 28 | void graphprinter_visit_binary_expr (struct _Visitor *, struct AstNode *); 29 | void graphprinter_visit_call (struct _Visitor *, struct AstNode *); 30 | void graphprinter_visit_callparam_list (struct _Visitor *, struct AstNode *); 31 | void graphprinter_visit_callparam (struct _Visitor *, struct AstNode *); 32 | void graphprinter_visit_identifier (struct _Visitor *, struct AstNode *); 33 | void graphprinter_visit_literal (struct _Visitor *, struct AstNode *); 34 | 35 | void graphprinter_visit_simplenode (struct _Visitor *, struct AstNode *); 36 | 37 | #endif // GRAPHPRINTER_VISITOR_H 38 | -------------------------------------------------------------------------------- /Pesquisa/ToyPascal/lextest.l: -------------------------------------------------------------------------------- 1 | %{ 2 | #include 3 | %} 4 | 5 | %% 6 | "Integer" printf("T_INTEGER "); 7 | "Var" printf("T_VAR "); 8 | "Begin" printf("T_BEGIN "); 9 | "End" printf("T_END "); 10 | "Procedure" printf("T_PROCEDURE "); 11 | "Function" printf("T_FUNCTION "); 12 | 13 | "*" printf("T_MULT "); 14 | "/" printf("T_DIV "); 15 | "+" printf("T_ADD "); 16 | "-" printf("T_SUB "); 17 | ":=" printf("T_ATTRIBUTION "); 18 | ";" printf("T_SEMICOLON "); 19 | ":" printf("T_COLON "); 20 | "." printf("T_DOT "); 21 | 22 | [0-9]+ printf("NUMBER "); 23 | [A-Za-z][A-Za-z0-9]* printf("IDENTIFIER "); 24 | 25 | [ \t]+ /* ignora whitespace */; 26 | \n printf("\n"); 27 | %% 28 | 29 | -------------------------------------------------------------------------------- /Pesquisa/ToyPascal/llvm_codegen_visitor.h: -------------------------------------------------------------------------------- 1 | #ifndef LLVM_CODEGEN_VISITOR_H 2 | #define LLVM_CODEGEN_VISITOR_H 3 | 4 | #include "ast.h" 5 | 6 | #define TAB " " 7 | #define PRINT_TYPE(t) if (t == VOID) printf("void"); \ 8 | else printf("i%d", _get_type_size(t)) 9 | 10 | #define PRINT_VALUE(n, i) if (n->kind == IDENTIFIER && n->parent->kind == PARAMETER) \ 11 | printf("%%%s", n->symbol->name); \ 12 | else { \ 13 | if (i == -1) printf("%d", ast_node_get_value_as_int(n)); \ 14 | else printf("%%%d", i); \ 15 | } 16 | 17 | static Symbol *symtab; 18 | static Symbol *global_symtab; 19 | 20 | Visitor *llvm_codegen_new(); 21 | 22 | void llvm_codegen_visit_program (struct _Visitor *, struct AstNode *); 23 | void llvm_codegen_visit_programdecl (struct _Visitor *, struct AstNode *); 24 | void llvm_codegen_visit_procfunc_list (struct _Visitor *, struct AstNode *); 25 | void llvm_codegen_visit_procfunc (struct _Visitor *, struct AstNode *); 26 | void llvm_codegen_visit_vardecl_list (struct _Visitor *, struct AstNode *); 27 | void llvm_codegen_visit_vardecl (struct _Visitor *, struct AstNode *); 28 | void llvm_codegen_visit_identifier_list (struct _Visitor *, struct AstNode *); 29 | void llvm_codegen_visit_param_list (struct _Visitor *, struct AstNode *); 30 | void llvm_codegen_visit_parameter (struct _Visitor *, struct AstNode *); 31 | void llvm_codegen_visit_statement_list(struct _Visitor *, struct AstNode *); 32 | void llvm_codegen_visit_printint_stmt (struct _Visitor *, struct AstNode *); 33 | void llvm_codegen_visit_printchar_stmt (struct _Visitor *, struct AstNode *); 34 | void llvm_codegen_visit_printbool_stmt (struct _Visitor *, struct AstNode *); 35 | void llvm_codegen_visit_printline_stmt (struct _Visitor *, struct AstNode *); 36 | void llvm_codegen_visit_assignment_stmt (struct _Visitor *, struct AstNode *); 37 | void llvm_codegen_visit_if_stmt (struct _Visitor *, struct AstNode *); 38 | void llvm_codegen_visit_while_stmt (struct _Visitor *, struct AstNode *); 39 | void llvm_codegen_visit_for_stmt (struct _Visitor *, struct AstNode *); 40 | void llvm_codegen_visit_binary_expr (struct _Visitor *, struct AstNode *); 41 | void llvm_codegen_visit_notfactor (struct _Visitor *, struct AstNode *); 42 | void llvm_codegen_visit_call (struct _Visitor *, struct AstNode *); 43 | void llvm_codegen_visit_callparam_list (struct _Visitor *, struct AstNode *); 44 | void llvm_codegen_visit_callparam (struct _Visitor *, struct AstNode *); 45 | void llvm_codegen_visit_identifier (struct _Visitor *, struct AstNode *); 46 | void llvm_codegen_visit_literal (struct _Visitor *, struct AstNode *); 47 | void llvm_codegen_visit_binary_op (struct _Visitor *, struct AstNode *); 48 | void llvm_codegen_visit_not_op (struct _Visitor *, struct AstNode *); 49 | 50 | #endif // LLVM_CODEGEN_VISITOR_H 51 | -------------------------------------------------------------------------------- /Pesquisa/ToyPascal/pascal/constants.pas: -------------------------------------------------------------------------------- 1 | program constants; 2 | 3 | Const pi: Integer = 3; 4 | 5 | Var c, d: Integer; 6 | 7 | Begin 8 | d := 5; 9 | c := pi * d; 10 | End. 11 | -------------------------------------------------------------------------------- /Pesquisa/ToyPascal/pascal/for.pas: -------------------------------------------------------------------------------- 1 | program forprog; 2 | 3 | var ch : char; 4 | var ch : integer; 5 | 6 | procedure test(); 7 | var a : integer; 8 | begin 9 | println() 10 | end; 11 | 12 | procedure forme(a : integer, b : boolean, c : char); 13 | var i, j : integer; 14 | begin 15 | j := 0; 16 | j := j * 5 + 1; 17 | 18 | z := 3; 19 | 20 | for i := 0 to a do 21 | begin 22 | j := j * 5 + 1; 23 | printint(j); 24 | println() 25 | end 26 | end; 27 | 28 | begin 29 | sbrubbles(); 30 | forme := 30; 31 | test(); 32 | ch := '1'; 33 | forme(); 34 | forme(111, 222); 35 | forme(3, true, ch); 36 | forme(7, 8, z); 37 | test(2) 38 | end. 39 | -------------------------------------------------------------------------------- /Pesquisa/ToyPascal/pascal/helloworld.pas: -------------------------------------------------------------------------------- 1 | program helloworld; 2 | 3 | Begin 4 | printchar('H'); 5 | printchar('e'); 6 | printchar('l'); 7 | printchar('l'); 8 | printchar('o'); 9 | printchar(' '); 10 | printchar('W'); 11 | printchar('o'); 12 | printchar('r'); 13 | printchar('l'); 14 | printchar('d'); 15 | End. 16 | -------------------------------------------------------------------------------- /Pesquisa/ToyPascal/pascal/if.pas: -------------------------------------------------------------------------------- 1 | program ifprog; 2 | 3 | Var i, k: integer; 4 | var bar : Boolean; 5 | 6 | procedure test (); 7 | var j : integer; 8 | var foo : boolean; 9 | begin 10 | i := 10; 11 | j := 3; 12 | 13 | printint(j); 14 | 15 | j := 77; 16 | 17 | printint(j); 18 | 19 | j := j * 77; 20 | 21 | printint(j); 22 | 23 | foo := false;{ and false;} 24 | 25 | if foo then 26 | printchar('t'); 27 | 28 | foo := true; 29 | 30 | if foo then 31 | printchar('t'); 32 | 33 | foo := false and true;{ and false;} 34 | 35 | if foo then 36 | printchar('t'); 37 | 38 | 39 | foo := true and false; 40 | foo := true or foo; 41 | foo := j > 2 * 2; 42 | foo := 3 < 4; 43 | foo := 5 >= 6; 44 | foo := 7 <= 8; 45 | foo := j = i; 46 | foo := j <> i 47 | end; 48 | 49 | begin 50 | bar := true; 51 | i := 17; 52 | 53 | if ((1 = 1) or (2 = 3)) and (bar = false) then 54 | begin 55 | printchar('t'); 56 | if bar then 57 | printchar ('B') 58 | end; 59 | 60 | if i > 3 * 6 then 61 | begin 62 | printchar('1'); 63 | if false then 64 | printchar('1') 65 | end 66 | else 67 | printchar('2'); 68 | 69 | test(); 70 | 71 | if (i = k) then if false then 72 | printint(i); 73 | 74 | test(); 75 | 76 | if bar then 77 | printchar('b'); 78 | 79 | println() 80 | end. 81 | -------------------------------------------------------------------------------- /Pesquisa/ToyPascal/pascal/ifandelze.pas: -------------------------------------------------------------------------------- 1 | program ifelse; 2 | 3 | Var 4 | i: Integer = 50; 5 | Begin 6 | if (i > 1 and i < 100) 7 | begin 8 | print('O'); 9 | print('k'); 10 | end 11 | else 12 | begin 13 | print('='); 14 | print('('); 15 | end 16 | End. 17 | -------------------------------------------------------------------------------- /Pesquisa/ToyPascal/pascal/sample0.pas: -------------------------------------------------------------------------------- 1 | program sample0; 2 | 3 | Var x : Integer; 4 | var b: Boolean; 5 | var c: char; 6 | 7 | FunCtion myfunc (i : integer, b : boolean) : integer; 8 | Begin 9 | {x := i + myfunc;} 10 | myfunc := i * 539 11 | {x := 300 + (3 + 2) * 7; 12 | i := 3; 13 | x := i * 5; 14 | i := x; 15 | x := 9 + 9; 16 | x := i; 17 | printint(i); 18 | i := 13 + 500; 19 | x := i - 1; 20 | i := i + 77; 21 | x := i + 1; 22 | x := 69; 23 | i := 17;} 24 | { := i + myfunc{FIXME: load i32* @myfunc, align 4} 25 | {myfunc := x}{FIXME} 26 | End; 27 | 28 | function getchar() : char; 29 | begin 30 | getchar := 'Z' 31 | end; 32 | 33 | function getbool() : boolean; 34 | begin 35 | getbool := true 36 | end; 37 | 38 | Procedure myproc (i : integer); 39 | {var ck, n : integer; 40 | var m : boolean;} 41 | var itsatrap : integer; 42 | var myhumps : integer; 43 | var myfunc : integer; 44 | Begin 45 | i := 4; 46 | myfunc := 3; 47 | myhumps := 250; 48 | 49 | itsatrap := x; 50 | itsatrap := myhumps; 51 | itsatrap := myfunc; 52 | myfunc := myfunc + 111; 53 | itsatrap := itsatrap + 1; 54 | itsatrap := myfunc(5, true); 55 | printbool(false); 56 | printchar('W'); 57 | printchar('\n'); 58 | printint(itsatrap); 59 | println(); 60 | itsatrap := myfunc(3, true); 61 | 62 | {ck := 5; 63 | ck := i * 2 + 3; 64 | ck := 11 + 22; 65 | {ck := 33 - ck; 66 | {ck := 44 * myfunc(55);} 67 | {m := false and true; 68 | x := ck; 69 | printint(ck); 70 | println(); 71 | printint(3 * 5); 72 | println(); 73 | printint(3); 74 | m := true or m; 75 | x := 5 + 5; 76 | println(); 77 | printint(i)} 78 | println() 79 | End; 80 | 81 | {FunCtion otherfunc (fint : Integer, fchar: Char) : Integer; 82 | var myvar : Boolean; 83 | var c : Char; 84 | Begin 85 | myvar := 34; 86 | c := '{'; 87 | End; 88 | } 89 | 90 | Begin 91 | x := 2 + 3; 92 | x := 2; 93 | {x := 2 + 3 * 5 + 9;} 94 | printint(x + 3 * 5 + 2); 95 | println(); 96 | myproc(7); 97 | x := 3 + myfunc(5, true); 98 | printint(x); 99 | x := 5 + myfunc(2, false); 100 | printint(x); 101 | {k := 30; 102 | {x := myfunc(65); 103 | {printbool(false); 104 | printchar('\n'); 105 | printchar('W'); 106 | println(); 107 | printint(137); 108 | println(); 109 | printint(x);} 110 | 111 | printint(myfunc(10, true)); 112 | 113 | c := getchar(); 114 | printchar(c); 115 | printchar(getchar()); 116 | 117 | b := getbool(); 118 | printbool(b); 119 | printbool(getbool()); 120 | printbool(true); 121 | 122 | println() 123 | End. 124 | 125 | -------------------------------------------------------------------------------- /Pesquisa/ToyPascal/pascal/sample1.pas: -------------------------------------------------------------------------------- 1 | program simple1; 2 | 3 | var a, b, c : integer; 4 | var n : boolean; 5 | 6 | FunCtion func2 () : Boolean; 7 | Begin 8 | func2 := true; 9 | End; 10 | 11 | FunCtion soma (a : integer, b : integer) : integer; 12 | Begin 13 | soma := a + b; 14 | End; 15 | 16 | Procedure proc2 (); 17 | var z : char; 18 | Begin 19 | z := 'Y'; 20 | End; 21 | 22 | Begin 23 | n := false; 24 | 25 | if n then 26 | begin 27 | a := soma(17, 3) * 70; 28 | end 29 | 30 | if n = true then 31 | begin 32 | c := (30 * a + 9 / 3) * n; 33 | end 34 | else 35 | begin 36 | d := func2(); 37 | end 38 | End. 39 | -------------------------------------------------------------------------------- /Pesquisa/ToyPascal/pascal/sample2.pas: -------------------------------------------------------------------------------- 1 | program sample2; 2 | 3 | var b: boolean; 4 | var c: char; 5 | var i, j: Integer; 6 | 7 | Procedure myproc (); 8 | var mp : boolean; 9 | Begin 10 | b := false; 11 | mp := not b; 12 | { 13 | printint(i); 14 | printchar(c); 15 | } 16 | printbool(mp); 17 | println() 18 | End; 19 | 20 | function myfunc (a : integer, b : integer) : integer; 21 | var mf1, mf2 : boolean; 22 | var mf3 : boolean; 23 | Begin 24 | mf1 := true; 25 | myfunc := a + b 26 | End; 27 | 28 | Begin 29 | c := 'z'; 30 | i := 13; 31 | j := 0; 32 | b := not false or (13 <> j); 33 | 34 | { 35 | while j <= 10 do 36 | begin 37 | printint(i); 38 | printchar(c); 39 | printbool(b); 40 | println() 41 | end; 42 | 43 | if b then 44 | printchar('v') 45 | else 46 | printchar('f'); 47 | 48 | for i := 2 * 3 to 10 + 1 do 49 | printint(i); 50 | } 51 | 52 | myproc(); 53 | j := myfunc(false, i); 54 | printint(j); 55 | 56 | i := 70 + 80 * 5 + 3; 57 | i := 1 * 2 + 3 * 4 58 | End. 59 | -------------------------------------------------------------------------------- /Pesquisa/ToyPascal/pascal/sample3.pas: -------------------------------------------------------------------------------- 1 | program sample3; 2 | 3 | var x : Integer; 4 | 5 | Procedure myproc (); 6 | var b : boolean; 7 | Begin 8 | b := false; 9 | x := 3 10 | End; 11 | 12 | Begin 13 | x := 70 * 5; 14 | println() 15 | End. 16 | -------------------------------------------------------------------------------- /Pesquisa/ToyPascal/pascal/sample4.pas: -------------------------------------------------------------------------------- 1 | program simple4; 2 | 3 | var a : integer; 4 | 5 | function test(i : integer) : integer; 6 | var t : integer; 7 | begin 8 | printint(i); 9 | println(); 10 | t := i; 11 | printint(t); 12 | test := 7; 13 | println() 14 | end; 15 | 16 | Begin 17 | {a := (3 < 2) and (b = 4) or (c > 3)} 18 | a := 250; 19 | printint(a); 20 | println(); 21 | 22 | a := test(13); 23 | 24 | println() 25 | End. 26 | -------------------------------------------------------------------------------- /Pesquisa/ToyPascal/pascal/sample5.pas: -------------------------------------------------------------------------------- 1 | program sample5; 2 | 3 | var i : integer; 4 | var c : char; 5 | 6 | procedure my_proc(); 7 | var b : boolean; 8 | begin 9 | b := true; 10 | printchar('t') 11 | end; 12 | 13 | function blah(c : char) : char; 14 | begin 15 | blah := 'z'; 16 | for i := 0 to 100 do 17 | begin 18 | printchar(c) 19 | end 20 | end; 21 | 22 | function getint() : integer; 23 | begin 24 | biz := 22; 25 | getint := 33 26 | end; 27 | 28 | function incr(i : integer) : integer; 29 | begin 30 | incr := i + 1 31 | end; 32 | 33 | function three(a : integer, b : integer, c : integer) : integer; 34 | begin 35 | three := a + b + getint() 36 | end; 37 | 38 | Begin 39 | i := getint(); 40 | printint(i); 41 | printint(getint()); 42 | 43 | i := incr(getint()); 44 | 45 | i := three(3, getint(), i); 46 | i := three(i, getint(), 55); 47 | 48 | printint(i); 49 | println(); 50 | 51 | blah('c'); 52 | blah(c); 53 | blah(blah()); 54 | blah(c); 55 | 56 | printchar(c); 57 | printchar('y'); 58 | printchar(blah(' ')); 59 | printint(three(3, i, getint())); 60 | 61 | println() 62 | End. 63 | 64 | 65 | -------------------------------------------------------------------------------- /Pesquisa/ToyPascal/pascal/variaveis.pas: -------------------------------------------------------------------------------- 1 | program variaveis; 2 | 3 | Var 4 | i: Integer; 5 | s: Char; 6 | b: Boolean; 7 | 8 | Begin 9 | i := -3; 10 | s := 'H'; 11 | b := True; 12 | End. 13 | -------------------------------------------------------------------------------- /Pesquisa/ToyPascal/pascal/variaveis2.pas: -------------------------------------------------------------------------------- 1 | program variaveis2; 2 | 3 | Var 4 | Num1, Num2, Ans: Integer; 5 | 6 | Begin 7 | Ans := 1 + 1; 8 | Num1 := 5; 9 | Ans := Num1 + 3; 10 | Num2 := 2; 11 | Ans := Num1 - Num2; 12 | Ans := Ans * Num1; 13 | End. 14 | -------------------------------------------------------------------------------- /Pesquisa/ToyPascal/pascal/while.pas: -------------------------------------------------------------------------------- 1 | program whileprog; 2 | 3 | var b: boolean; 4 | var i: Integer; 5 | 6 | begin 7 | i := 0; 8 | 9 | while i <= 10 do 10 | i := i + 1; 11 | 12 | b := true; 13 | 14 | while b do 15 | begin 16 | printboolean(b); 17 | b := false 18 | end; 19 | 20 | printboolean(b) 21 | end. 22 | -------------------------------------------------------------------------------- /Pesquisa/ToyPascal/scanner.l: -------------------------------------------------------------------------------- 1 | %{ 2 | #include 3 | #include "base.h" 4 | #include "parser.h" 5 | 6 | #define uploc { yylloc->first_column = yylloc->last_column + 1; yylloc->last_column += yyleng; } 7 | 8 | #define CAST_BOOLEAN(strb) strcasecmp(strb, "False") ? TRUE : FALSE 9 | /*#define YY_DECL int yylex (YYSTYPE *yylval_param)*/ 10 | %} 11 | 12 | %option yylineno 13 | %option bison-bridge 14 | %option bison-locations 15 | %option noyywrap 16 | %option nounput 17 | %option case-insensitive 18 | 19 | %% 20 | "{" { int c; 21 | while ((c = input())) { 22 | if (c == '}') 23 | break; 24 | else if (c == '\n') { 25 | yylloc->first_line = yylloc->last_line = yylineno; 26 | yylloc->first_column = 1; 27 | yylloc->last_column = 0; 28 | } else if (c == EOF) { 29 | fprintf (stderr, 30 | "Error: unexpected EOF inside comment " 31 | "at line %d\n", 32 | yylineno); 33 | exit (1); 34 | } 35 | } 36 | } 37 | "program" { uploc; return T_PROGRAM; } 38 | "var" { uploc; return T_VAR; } 39 | "integer"|"boolean"|"char" { uploc; 40 | yylval->type = type_get_from_lexeme(yytext); 41 | return TYPE_IDENTIFIER; 42 | } 43 | 44 | "procedure" { uploc; return T_PROCEDURE; } 45 | "function" { uploc; return T_FUNCTION; } 46 | "begin" { uploc; return T_BEGIN; } 47 | "end" { uploc; return T_END; } 48 | 49 | "printInt" { uploc; return T_PRINT_INT; } 50 | "printBool" { uploc; return T_PRINT_BOOL; } 51 | "printChar" { uploc; return T_PRINT_CHAR; } 52 | "println" { uploc; return T_PRINT_LINE; } 53 | 54 | "if" { uploc; return T_IF; } 55 | "then" { uploc; return T_THEN; } 56 | "else" { uploc; return T_ELSE; } 57 | "while" { uploc; return T_WHILE; } 58 | "for" { uploc; return T_FOR; } 59 | "to" { uploc; return T_TO; } 60 | "do" { uploc; return T_DO; } 61 | 62 | ":=" { uploc; return T_ASSIGNMENT; } 63 | "(" { uploc; return T_LPAR; } 64 | ")" { uploc; return T_RPAR; } 65 | "+" { uploc; yylval->lexeme=strdup(yytext); 66 | return T_PLUS; 67 | } 68 | "-" { uploc; yylval->lexeme=strdup(yytext); 69 | return T_MINUS; 70 | } 71 | "*" { uploc; yylval->lexeme=strdup(yytext); 72 | return T_STAR; 73 | } 74 | "/" { uploc; yylval->lexeme=strdup(yytext); 75 | return T_SLASH; 76 | } 77 | "and" { uploc; yylval->lexeme=strdup(yytext); 78 | return T_AND; 79 | } 80 | "or" { uploc; yylval->lexeme=strdup(yytext); 81 | return T_OR; 82 | } 83 | "not" { uploc; yylval->lexeme=strdup(yytext); 84 | return T_NOT; 85 | } 86 | ">" { uploc; yylval->lexeme=strdup(yytext); 87 | return T_GREATER; 88 | } 89 | "<" { uploc; yylval->lexeme=strdup(yytext); 90 | return T_LESSER; 91 | } 92 | "=" { uploc; yylval->lexeme=strdup(yytext); 93 | return T_EQUAL; 94 | } 95 | "<>" { uploc; yylval->lexeme=strdup(yytext); 96 | return T_NOTEQUAL; 97 | } 98 | ">=" { uploc; yylval->lexeme=strdup(yytext); 99 | return T_GREATEREQUAL; 100 | } 101 | "<=" { uploc; yylval->lexeme=strdup(yytext); 102 | return T_LESSEREQUAL; 103 | } 104 | 105 | ";" { uploc; return T_SEMICOLON; } 106 | ":" { uploc; return T_COLON; } 107 | "." { uploc; return T_DOT; } 108 | "," { uploc; return T_COMMA; } 109 | 110 | "true"|"false" { uploc; 111 | yylval->boolean=CAST_BOOLEAN(yytext); 112 | return BOOL_LITERAL; 113 | } 114 | "'"\\n"'" { uploc; yylval->character='\n'; 115 | return CHAR_LITERAL; 116 | } 117 | "'"."'" { uploc; yylval->character=yytext[1]; 118 | return CHAR_LITERAL; 119 | } 120 | [0-9]+ { uploc; yylval->integer=atoi(yytext); 121 | return INT_LITERAL; 122 | } 123 | [A-Za-z][A-Za-z0-9_]* { uploc; yylval->lexeme=strdup(yytext); 124 | return IDENTIFIER; 125 | } 126 | 127 | [ \t]+ /* ignora whitespace */; 128 | [\n] { yylloc->first_line = yylloc->last_line = yylineno; 129 | yylloc->first_column = 1; 130 | yylloc->last_column = 0; 131 | } 132 | 133 | . { uploc; 134 | fprintf (stderr, 135 | "Syntax Error: unexpected " 136 | "character '%s' at line %d\n", 137 | yytext, yylloc->first_line); 138 | } 139 | 140 | 141 | %% 142 | -------------------------------------------------------------------------------- /Pesquisa/ToyPascal/simpleprinter_visitor.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include "base.h" 4 | #include "simpleprinter_visitor.h" 5 | 6 | Visitor * 7 | simpleprinter_new() 8 | { 9 | Visitor *visitor = (Visitor *) malloc (sizeof(Visitor)); 10 | 11 | visitor->visit_program = &simpleprinter_visit; 12 | visitor->visit_programdecl = &simpleprinter_visit; 13 | visitor->visit_vardecl_list = &simpleprinter_visit; 14 | visitor->visit_vardecl = &simpleprinter_visit; 15 | visitor->visit_identifier_list = &simpleprinter_visit; 16 | visitor->visit_procfunc_list = &simpleprinter_visit; 17 | visitor->visit_procedure = &simpleprinter_visit; 18 | visitor->visit_function = &simpleprinter_visit; 19 | visitor->visit_param_list = &simpleprinter_visit; 20 | visitor->visit_parameter = &simpleprinter_visit; 21 | visitor->visit_statement_list = &simpleprinter_visit; 22 | visitor->visit_printint_stmt = &simpleprinter_visit; 23 | visitor->visit_printchar_stmt = &simpleprinter_visit; 24 | visitor->visit_printbool_stmt = &simpleprinter_visit; 25 | visitor->visit_printline_stmt = &simpleprinter_visit; 26 | visitor->visit_assignment_stmt = &simpleprinter_visit; 27 | visitor->visit_if_stmt = &simpleprinter_visit; 28 | visitor->visit_while_stmt = &simpleprinter_visit; 29 | visitor->visit_for_stmt = &simpleprinter_visit; 30 | visitor->visit_rel_expr = &simpleprinter_visit; 31 | visitor->visit_add_expr = &simpleprinter_visit; 32 | visitor->visit_mul_expr = &simpleprinter_visit; 33 | visitor->visit_notfactor = &simpleprinter_visit; 34 | visitor->visit_call = &simpleprinter_visit; 35 | visitor->visit_callparam_list = &simpleprinter_visit; 36 | visitor->visit_identifier = &simpleprinter_visit; 37 | visitor->visit_literal = &simpleprinter_visit; 38 | visitor->visit_add_op = &simpleprinter_visit; 39 | visitor->visit_mul_op = &simpleprinter_visit; 40 | visitor->visit_rel_op = &simpleprinter_visit; 41 | visitor->visit_not_op = &simpleprinter_visit; 42 | 43 | return visitor; 44 | } 45 | 46 | void 47 | simpleprinter_visit(struct _Visitor *visitor, struct AstNode *node) 48 | { 49 | int i; 50 | struct AstNode *temp; 51 | 52 | if (node == NULL) 53 | return; 54 | 55 | printf("(AstNode) %x : %s\n", node, node->name); 56 | printf("kind: %d\n", node->kind); 57 | printf("type: %d\n", node->type); 58 | printf("value: "); 59 | value_print(stdout, &node->value, node->type); 60 | printf("\nlinenum: %d\n", node->linenum); 61 | if (node->symbol != NULL) 62 | printf("symbol: %x (\"%s\")\n", node->symbol, node->symbol->name); 63 | 64 | printf("Parent: (AstNode) %x\n", node->parent); 65 | 66 | if (node->children != NULL) { 67 | printf("Children\n"); 68 | for (temp = node->children; temp != NULL; temp = temp->sibling) { 69 | printf("\t(AstNode) %x", temp); 70 | if (temp->name != NULL) 71 | printf(" : %s", temp->name); 72 | printf("\n"); 73 | } 74 | } 75 | printf("\n"); 76 | 77 | ast_node_accept_children(node->children, visitor); 78 | } 79 | -------------------------------------------------------------------------------- /Pesquisa/ToyPascal/simpleprinter_visitor.h: -------------------------------------------------------------------------------- 1 | #ifndef SIMPLEPRINTER_VISITOR_H 2 | #define SIMPLEPRINTER_VISITOR_H 3 | 4 | #include "ast.h" 5 | 6 | Visitor *simpleprinter_new(); 7 | 8 | void simpleprinter_visit (struct _Visitor *, struct AstNode *); 9 | 10 | #endif // SIMPLEPRINTER_VISITOR_H 11 | -------------------------------------------------------------------------------- /Pesquisa/ToyPascal/symbol_table.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include "symbol_table.h" 5 | 6 | Symbol * 7 | symbol_new(char const * name) 8 | { 9 | Symbol * symbol = (Symbol *) malloc (sizeof(Symbol)); 10 | symbol->type = VOID; 11 | value_set(&symbol->value, symbol->type, NULL); 12 | symbol->params = -1; 13 | symbol->param_types = NULL; 14 | symbol->decl_linenum = 0; 15 | symbol->is_global = FALSE; 16 | symbol->stack_index = -1; 17 | 18 | symbol->next = NULL; 19 | 20 | if (name != NULL) 21 | symbol->name = strdup(name); 22 | else 23 | symbol->name = NULL; 24 | 25 | return symbol; 26 | } 27 | 28 | /* Insere um simbolo na tabela indicada. 29 | * Caso o simbolo ja exista, a memoria do 30 | * simbolo do parametro sera liberada. 31 | * Returns: O simbolo passado como parametro, 32 | * caso este ainda nao esteja na tabela, 33 | * ou um ponteiro para o simbolo encontrado. 34 | */ 35 | Symbol * 36 | symbol_insert(Symbol *symtab, Symbol *symbol) 37 | { 38 | Symbol *sym; 39 | 40 | if (symbol == NULL) 41 | return NULL; 42 | 43 | sym = symbol_lookup(symtab, symbol->name); 44 | 45 | if (sym != NULL) { 46 | free(symbol->name); 47 | free(symbol); 48 | return sym; 49 | } 50 | 51 | symbol->next = symtab->next; 52 | symtab->next = symbol; 53 | 54 | return symbol; 55 | } 56 | 57 | Symbol * 58 | symbol_lookup(Symbol *symtab, char const *name) 59 | { 60 | Symbol *temp; 61 | 62 | if (symtab == NULL) 63 | return NULL; 64 | 65 | for (temp = symtab->next; temp != NULL; temp = temp->next) { 66 | if (!strcmp (temp->name, name)) 67 | return temp; 68 | } 69 | 70 | return temp; 71 | } 72 | 73 | void 74 | symbol_table_destroy(Symbol *symtab) 75 | { 76 | Symbol *first; 77 | Symbol *to_kill; 78 | first = symtab->next; 79 | symtab->next = NULL; 80 | 81 | while (first != NULL) { 82 | to_kill = first; 83 | first = first->next; 84 | if (to_kill->name != NULL) 85 | free(to_kill->name); 86 | free(to_kill); 87 | } 88 | } 89 | 90 | void 91 | symbol_create_params(Symbol *symbol, int quantity) 92 | { 93 | symbol->params = quantity; 94 | if (quantity > 0) 95 | symbol->param_types = (int *) malloc (sizeof(int) * quantity); 96 | } 97 | 98 | bool 99 | symbol_is_procfunc(Symbol *symbol) 100 | { 101 | return (symbol->params > -1); 102 | } 103 | 104 | void 105 | symbol_print(Symbol *symbol) 106 | { 107 | if (symbol == NULL) { 108 | printf("NULL\n\n"); 109 | return; 110 | } 111 | 112 | printf("Symbol: %x\n", symbol); 113 | printf("name: %s\n", symbol->name); 114 | printf("type: %d\n", symbol->type); 115 | printf("value:"); 116 | value_print(stdout, &symbol->value, symbol->type); 117 | printf("\ndeclaration line: %d\n", symbol->decl_linenum); 118 | printf("next: %x\n\n", symbol->next); 119 | } 120 | 121 | void 122 | symbol_table_dump(Symbol *symtab) 123 | { 124 | Symbol *temp = symtab; 125 | 126 | for (temp = symtab->next; temp != NULL; temp = temp->next) 127 | symbol_print(temp); 128 | } 129 | -------------------------------------------------------------------------------- /Pesquisa/ToyPascal/symbol_table.h: -------------------------------------------------------------------------------- 1 | #ifndef SYMBOL_TABLE_H 2 | #define SYMBOL_TABLE_H 3 | 4 | #include "base.h" 5 | 6 | typedef struct _symbol { 7 | char *name; 8 | Type type; 9 | Value value; 10 | int decl_linenum; 11 | 12 | // For procedures and functions 13 | int params; 14 | Type *param_types; 15 | 16 | bool is_global; 17 | int stack_index; 18 | struct _symbol *next; 19 | } Symbol; 20 | 21 | static Symbol *global_symbol_table; 22 | 23 | Symbol *symbol_new(char const * name); 24 | Symbol *symbol_lookup(Symbol *symtab, char const *name); 25 | Symbol *symbol_insert(Symbol *symtab, Symbol *symbol); 26 | 27 | void symbol_create_params(Symbol *symbol, int quantity); 28 | bool symbol_is_procfunc(Symbol *symbol); 29 | void symbol_print(Symbol *symbol); 30 | 31 | void symbol_table_destroy(Symbol *table); 32 | void symbol_table_dump(Symbol *table); 33 | 34 | #endif // SYMBOL_TABLE_H 35 | -------------------------------------------------------------------------------- /Pesquisa/ToyPascal/typecheck_visitor.h: -------------------------------------------------------------------------------- 1 | #ifndef TYPECHECK_VISITOR_H 2 | #define TYPECHECK_VISITOR_H 3 | 4 | #include "ast.h" 5 | #include "base.h" 6 | #include "symbol_table.h" 7 | 8 | //static bool is_vardecl = FALSE; 9 | static Type declared_type = VOID; 10 | static Symbol *symtab; 11 | static Symbol *global_symtab; 12 | 13 | Visitor *typecheck_new(); 14 | 15 | void typecheck_visit_program (struct _Visitor *, struct AstNode *); 16 | void typecheck_visit_programdecl (struct _Visitor *, struct AstNode *); 17 | void typecheck_visit_procfunc_list (struct _Visitor *, struct AstNode *); 18 | void typecheck_visit_procfunc(struct _Visitor *, struct AstNode *); 19 | void typecheck_visit_vardecl_list (struct _Visitor *, struct AstNode *); 20 | void typecheck_visit_vardecl (struct _Visitor *, struct AstNode *); 21 | void typecheck_visit_param_list(struct _Visitor *, struct AstNode *); 22 | void typecheck_visit_parameter (struct _Visitor *, struct AstNode *); 23 | void typecheck_visit_statement_list(struct _Visitor *, struct AstNode *); 24 | void typecheck_visit_printint_stmt (struct _Visitor *, struct AstNode *); 25 | void typecheck_visit_printchar_stmt (struct _Visitor *, struct AstNode *); 26 | void typecheck_visit_printbool_stmt (struct _Visitor *, struct AstNode *); 27 | void typecheck_visit_printline_stmt (struct _Visitor *, struct AstNode *); 28 | void typecheck_visit_assignment_stmt (struct _Visitor *, struct AstNode *); 29 | void typecheck_visit_if_stmt (struct _Visitor *, struct AstNode *); 30 | void typecheck_visit_while_stmt (struct _Visitor *, struct AstNode *); 31 | void typecheck_visit_for_stmt (struct _Visitor *, struct AstNode *); 32 | void typecheck_visit_binary_expr (struct _Visitor *, struct AstNode *); 33 | void typecheck_visit_notfactor (struct _Visitor *, struct AstNode *); 34 | void typecheck_visit_call (struct _Visitor *, struct AstNode *); 35 | void typecheck_visit_callparam_list (struct _Visitor *, struct AstNode *); 36 | void typecheck_visit_callparam (struct _Visitor *, struct AstNode *); 37 | void typecheck_visit_identifier_list(struct _Visitor *, struct AstNode *); 38 | void typecheck_visit_identifier (struct _Visitor *, struct AstNode *); 39 | 40 | #endif // TYPECHECK_VISITOR_H 41 | -------------------------------------------------------------------------------- /Pesquisa/Writing a compiler using Python, Lex, Yacc and LLVM by Alcides Fonseca_arquivos/alcides-bliki.css: -------------------------------------------------------------------------------- 1 | /* Reset */ 2 | 3 | * { 4 | padding: 0; 5 | margin: 0; 6 | } 7 | 8 | .clear { 9 | clear: both; 10 | } 11 | 12 | /* Typography */ 13 | 14 | body { 15 | font-family: Helvetica, sans-serif; 16 | font-size: 12px; 17 | line-height: 16px; 18 | } 19 | 20 | p { 21 | margin-bottom: 16px; 22 | } 23 | 24 | blockquote { 25 | border-left: solid #8FA193 5px; 26 | padding-left: 5px; 27 | font-size: 15px; 28 | font-style: italic; 29 | font-family: Georgia; 30 | } 31 | 32 | b { 33 | font-variant: small-caps; 34 | } 35 | 36 | h1 { 37 | font-size: 48px; 38 | line-height: 50px; 39 | font-weight: normal; 40 | } 41 | 42 | h2 { 43 | font-size: 36px; 44 | line-height: 40px; 45 | text-transform: uppercase; 46 | } 47 | 48 | h3 { 49 | font-size: 24px; 50 | line-height: 30px; 51 | } 52 | 53 | h4 { 54 | font-size: 21px; 55 | line-height: 25px; 56 | } 57 | 58 | h5 { 59 | font-size: 18px; 60 | line-height: 20px; 61 | } 62 | 63 | h6 { 64 | font-size: 16px; 65 | line-height: 18px; 66 | } 67 | 68 | h1, h2, h3, h4, h5, h6 { 69 | margin-top: 5px; 70 | } 71 | 72 | ul { 73 | margin: 5px; 74 | margin-bottom: 10px; 75 | } 76 | 77 | /* Color */ 78 | 79 | a { 80 | color: #45594E; 81 | text-decoration: none; 82 | } 83 | 84 | a:hover { 85 | background-color: #F4F3DE; 86 | color: #3B4137; 87 | } 88 | 89 | .footnote { 90 | font-size: 8pt; 91 | } 92 | 93 | /* Layout */ 94 | 95 | ul { 96 | list-style-position: inside; 97 | } 98 | 99 | .wrap { 100 | max-width: 800px; 101 | margin: auto; 102 | } 103 | 104 | header { 105 | width: 100%; 106 | background-color: #12140F; 107 | margin-bottom: 20px; 108 | padding-top: 5px; 109 | padding-bottom: 5px; 110 | display: block; 111 | } 112 | 113 | header a { 114 | color: white; 115 | text-decoration: none; 116 | background-color: #12140F; 117 | } 118 | 119 | header a:hover { 120 | background-color: #12140F; 121 | color: #CCCCCC; 122 | } 123 | 124 | .author { 125 | margin: auto; 126 | margin-left: 10%; 127 | text-align: left; 128 | } 129 | 130 | .author h1 { 131 | float: left; 132 | text-align: left; 133 | } 134 | 135 | .author h1 a { 136 | display: block; 137 | padding-top: 15px; 138 | } 139 | 140 | .author img.photo { 141 | float: left; 142 | margin: 5px; 143 | margin-right: 3%; 144 | } 145 | 146 | .author .links { 147 | float: right; 148 | margin-top: 25px; 149 | margin-right: 30px; 150 | } 151 | 152 | .author .links li { 153 | list-style: none; 154 | float: right; 155 | } 156 | 157 | .author .links li a { 158 | display: block; 159 | padding: 3px; 160 | margin: 5pt; 161 | width: auto; 162 | } 163 | 164 | .author .links li a:hover { 165 | background-color: #333333; 166 | } 167 | 168 | footer { 169 | display: block; 170 | padding: 5px; 171 | padding-top: 10px; 172 | width: 50%; 173 | margin: auto; 174 | margin-top: 20px; 175 | clear: both; 176 | text-align: center; 177 | background-color: #8FA193; 178 | color: #12140F; 179 | } 180 | 181 | 182 | .entry-title { 183 | margin-top: 30px; 184 | margin-left: 10%; 185 | } 186 | 187 | .entry-title a { 188 | text-decoration: none; 189 | font-weight: normal; 190 | background-color: #8FA193; 191 | color: white; 192 | padding: 3px; 193 | } 194 | 195 | .updated { 196 | margin-top: 10px; 197 | } 198 | 199 | .date { 200 | text-align: center; 201 | } 202 | 203 | .date .year, .date .month, .date .day { 204 | display: block; 205 | color: #45594E; 206 | font-weight: bold; 207 | margin-bottom:10px; 208 | } 209 | 210 | .date .year { 211 | font-size: 12pt; 212 | } 213 | .date .month { 214 | font-size: 14pt; 215 | } 216 | .date .day { 217 | font-size: 26pt; 218 | } 219 | 220 | 221 | .details { 222 | float: left; 223 | margin-left: 3%; 224 | margin-right: 2%; 225 | width: 5%; 226 | margin-top: 5px; 227 | text-align: right; 228 | } 229 | 230 | .text { 231 | margin-top: 10px; 232 | float: left; 233 | width: 82%; 234 | text-align: justify; 235 | font-size: 14px; 236 | line-height: 16px; 237 | } 238 | 239 | .subpages h5 { 240 | padding-top: 15px; 241 | padding-bottom: 5px; 242 | } 243 | 244 | .subpages, .comments, .ads { 245 | clear: both; 246 | margin-left: 10%; 247 | margin-bottom: 20px; 248 | } 249 | 250 | .subpages li a:hover { 251 | color: red; 252 | } 253 | 254 | .subpages li { 255 | list-style: none; 256 | margin-top: 3px; 257 | margin-bottom: 3px; 258 | } 259 | 260 | .pagination { 261 | width: 100%; 262 | margin: auto; 263 | margin-top: 20px; 264 | margin-bottom: 20px; 265 | border-top: solid #45594E 1px; 266 | padding-top: 10px; 267 | } 268 | 269 | .pagination .previous { 270 | float: left; 271 | } 272 | 273 | .pagination .next { 274 | float: right; 275 | } 276 | 277 | .pagination a { 278 | display: block inline; 279 | padding: 3px; 280 | border: solid #45594E 1px; 281 | } 282 | -------------------------------------------------------------------------------- /Pesquisa/Writing a compiler using Python, Lex, Yacc and LLVM by Alcides Fonseca_arquivos/alcides_small.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wanderlan/llvm-pascal/19fda52906749ee0bd05d0e0c1d81d2806b7d263/Pesquisa/Writing a compiler using Python, Lex, Yacc and LLVM by Alcides Fonseca_arquivos/alcides_small.png -------------------------------------------------------------------------------- /Pesquisa/Writing a compiler using Python, Lex, Yacc and LLVM by Alcides Fonseca_arquivos/auryn1gif1_normal.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wanderlan/llvm-pascal/19fda52906749ee0bd05d0e0c1d81d2806b7d263/Pesquisa/Writing a compiler using Python, Lex, Yacc and LLVM by Alcides Fonseca_arquivos/auryn1gif1_normal.png -------------------------------------------------------------------------------- /Pesquisa/Writing a compiler using Python, Lex, Yacc and LLVM by Alcides Fonseca_arquivos/avatar92.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wanderlan/llvm-pascal/19fda52906749ee0bd05d0e0c1d81d2806b7d263/Pesquisa/Writing a compiler using Python, Lex, Yacc and LLVM by Alcides Fonseca_arquivos/avatar92.jpg -------------------------------------------------------------------------------- /Pesquisa/Writing a compiler using Python, Lex, Yacc and LLVM by Alcides Fonseca_arquivos/avatar92_002.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wanderlan/llvm-pascal/19fda52906749ee0bd05d0e0c1d81d2806b7d263/Pesquisa/Writing a compiler using Python, Lex, Yacc and LLVM by Alcides Fonseca_arquivos/avatar92_002.jpg -------------------------------------------------------------------------------- /Pesquisa/Writing a compiler using Python, Lex, Yacc and LLVM by Alcides Fonseca_arquivos/avatar92_003.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wanderlan/llvm-pascal/19fda52906749ee0bd05d0e0c1d81d2806b7d263/Pesquisa/Writing a compiler using Python, Lex, Yacc and LLVM by Alcides Fonseca_arquivos/avatar92_003.jpg -------------------------------------------------------------------------------- /Pesquisa/Writing a compiler using Python, Lex, Yacc and LLVM by Alcides Fonseca_arquivos/avatar92_004.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wanderlan/llvm-pascal/19fda52906749ee0bd05d0e0c1d81d2806b7d263/Pesquisa/Writing a compiler using Python, Lex, Yacc and LLVM by Alcides Fonseca_arquivos/avatar92_004.jpg -------------------------------------------------------------------------------- /Pesquisa/Writing a compiler using Python, Lex, Yacc and LLVM by Alcides Fonseca_arquivos/bullet-feed.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wanderlan/llvm-pascal/19fda52906749ee0bd05d0e0c1d81d2806b7d263/Pesquisa/Writing a compiler using Python, Lex, Yacc and LLVM by Alcides Fonseca_arquivos/bullet-feed.png -------------------------------------------------------------------------------- /Pesquisa/Writing a compiler using Python, Lex, Yacc and LLVM by Alcides Fonseca_arquivos/disqus-logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wanderlan/llvm-pascal/19fda52906749ee0bd05d0e0c1d81d2806b7d263/Pesquisa/Writing a compiler using Python, Lex, Yacc and LLVM by Alcides Fonseca_arquivos/disqus-logo.png -------------------------------------------------------------------------------- /Pesquisa/Writing a compiler using Python, Lex, Yacc and LLVM by Alcides Fonseca_arquivos/email.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wanderlan/llvm-pascal/19fda52906749ee0bd05d0e0c1d81d2806b7d263/Pesquisa/Writing a compiler using Python, Lex, Yacc and LLVM by Alcides Fonseca_arquivos/email.png -------------------------------------------------------------------------------- /Pesquisa/Writing a compiler using Python, Lex, Yacc and LLVM by Alcides Fonseca_arquivos/embed.js: -------------------------------------------------------------------------------- 1 | var disqus_href=window.location.href;var disqus_date=new Date();var disqus_hashIndex=disqus_href.indexOf("#");if(disqus_hashIndex!=-1){disqus_href=disqus_href.substring(0,disqus_hashIndex)}var DsqCache={};var disqus_script=document.createElement("script");var disqus_shortname,disqus_domain;var disqus_url,disqus_title,disqus_message,disqus_sort,disqus_dev;var disqus_container_id,disqus_category_id,disqus_developer;var disqus_identifier,disqus_frame_theme;var disqus_extra_qs="";var disqus_shortname_re=[/https?:\/\/(www\.)?disqus\.com\/forums\/([\w_\-]+)/i,/https?:\/\/(www\.)?([\w_\-]+)\.disqus\.com/i,/https?:\/\/(www\.)?dev\.disqus\.org\/forums\/([\w_\-]+)/i];var disqus_browser={ie:/msie/i.test(navigator.userAgent)&&!/opera/i.test(navigator.userAgent),ie6:(!window.XMLHttpRequest)?true:false,ie7:(document.all&&!window.opera&&window.XMLHttpRequest)?true:false};var disqus_detect_shortname=function(){var d=function(g){var h=(g.getAttribute)?g.getAttribute("src"):g.src;if(h){for(var f=0;f=0;c--){var b=d(a[c]);if(b!==null){return b}}return null};if(typeof(disqus_url)=="undefined"||disqus_url==""){disqus_url=disqus_href}if(typeof(disqus_title)=="undefined"){disqus_title=""}if(typeof(disqus_message)=="undefined"){disqus_message=""}else{var disqus_isUTF8=false;if(/msie/i.test(navigator.userAgent)&&!/opera/i.test(navigator.userAgent)){for(var i=0;i256){disqus_isUTF8=true;break}}}if(disqus_isUTF8){disqus_message=""}else{if(disqus_message.length>400){disqus_message=disqus_message.substring(0,disqus_message.indexOf(" ",350))}}}if(typeof(disqus_sort)=="undefined"){disqus_sort=""}if(typeof(disqus_container_id)=="undefined"){disqus_container_id="disqus_thread"}if(typeof(disqus_category_id)=="undefined"){disqus_category_id=""}if(typeof(disqus_developer)=="undefined"){disqus_developer=""}if(typeof(disqus_identifier)=="undefined"){disqus_identifier=""}if(typeof(disqus_require_moderation_s)!="undefined"){disqus_extra_qs+="&require_mod_s="+encodeURIComponent(disqus_require_moderation_s)}if(typeof(disqus_remote_auth_s2)!="undefined"){disqus_extra_qs+="&remote_auth_s2="+encodeURIComponent(disqus_remote_auth_s2)}if(typeof(disqus_per_page)!="undefined"){disqus_extra_qs+="&per_page="+encodeURIComponent(disqus_per_page)}if(typeof(disqus_author_s2)!="undefined"){disqus_extra_qs+="&author_s2="+encodeURIComponent(disqus_author_s2)}if(typeof(disqus_shortname)=="undefined"){disqus_shortname=disqus_detect_shortname()}if(typeof(disqus_domain)=="undefined"){disqus_domain=disqus_dev?"dev.disqus.org":"disqus.com"}var disqus_head=document.getElementsByTagName("head")[0];if(!disqus_head){disqus_head=document.getElementById("disqus_thread")}var disqus_styles=document.createElement("style");disqus_head.appendChild(disqus_styles);DsqCache.inlineStylesheet=disqus_styles.sheet;if(!DsqCache.inlineStylesheet){DsqCache.inlineStylesheet=document.styleSheets[document.styleSheets.length-1]}var disqus_stylesheet=document.createElement("link");disqus_stylesheet.rel="stylesheet";disqus_stylesheet.type="text/css";disqus_stylesheet.href="http://"+disqus_domain+"/forums/"+disqus_shortname+"/styles.css";if(disqus_browser.ie6||disqus_browser.ie7){disqus_stylesheet.href+="?b="+(disqus_browser.ie6?"ie6":"ie7")}disqus_head.appendChild(disqus_stylesheet);disqus_script.type="text/javascript";disqus_script.src="http://"+disqus_shortname+"."+disqus_domain+"/thread.js?url="+encodeURIComponent(disqus_url)+"&message="+encodeURIComponent(disqus_message)+"&title="+encodeURIComponent(disqus_title)+"&sort="+encodeURIComponent(disqus_sort)+"&category_id="+encodeURIComponent(disqus_category_id)+"&developer="+((disqus_developer=="0"||!disqus_developer)?0:1)+"&identifier="+encodeURIComponent(disqus_identifier)+disqus_extra_qs+"&"+disqus_date.getTime();disqus_script.charset="UTF-8";var dsq_report_staticjs_problem=function(){var a=document.getElementById("dsq-content-stub");a.innerHTML='';e.receiver=document.getElementById(i).contentWindow;e.packetHandler=new PostMessagePacket(e.receiver,b,j,i);e._listener=e.packetHandler.createListener()};if(typeof window.postMessage=="function"){c()}else{f()}};ParentMessenger.prototype.sendMessage=function(b){var a=this;if(!this._ready){window.setTimeout(function(){a.sendMessage(b)},10);return}this.packetHandler.send(b);return true}; -------------------------------------------------------------------------------- /Pesquisa/Writing a compiler using Python, Lex, Yacc and LLVM by Alcides Fonseca_arquivos/noavatar92.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wanderlan/llvm-pascal/19fda52906749ee0bd05d0e0c1d81d2806b7d263/Pesquisa/Writing a compiler using Python, Lex, Yacc and LLVM by Alcides Fonseca_arquivos/noavatar92.png -------------------------------------------------------------------------------- /Pesquisa/Writing a compiler using Python, Lex, Yacc and LLVM by Alcides Fonseca_arquivos/reply_data/httpjson.js: -------------------------------------------------------------------------------- 1 | /* $AJR(...) 2 | * Asynchronous JSON Request 3 | * Only to be used with trusted URLS 4 | */ 5 | // TODO require method. 6 | var $AJR = function(url, callbacks, postData, method, async) { 7 | var parseJSON = function(json) { 8 | if(json === null || json === '' || (/^\s+$/).test(json)) { 9 | return null; 10 | } 11 | return eval('(' + json + ')'); 12 | }; 13 | 14 | var encodeData = function(data) { 15 | if (data === null) { 16 | return null; 17 | } 18 | 19 | var pairs = []; 20 | var re = /%20/g; 21 | for (var name in data) { 22 | if (data.hasOwnProperty(name)) { 23 | var value = data[name].toString(); 24 | var pair = encodeURIComponent(name).replace(re, '+') + '=' + encodeURIComponent(value).replace(re, '+'); 25 | pairs.push(pair); 26 | } 27 | } 28 | return pairs.join('&'); 29 | }; 30 | 31 | var getRequest = function() { 32 | var factories = [ 33 | function() { return new XMLHttpRequest(); }, 34 | function() { return new ActiveXObject('Msxml2.XMLHTTP'); }, 35 | function() { return new ActiveXObject('Microsoft.XMLHTTP'); } 36 | ]; 37 | 38 | for (var i = 0; i < factories.length; i++) { 39 | try { 40 | request = factories[i](); 41 | if (request !== null) { 42 | return request; 43 | } 44 | } catch(e) { 45 | continue; 46 | } 47 | } 48 | 49 | return null; 50 | }; 51 | 52 | if(typeof(method) == 'undefined') { 53 | method = 'post'; 54 | } 55 | 56 | if(typeof(callbacks) == 'undefined') { 57 | callbacks = {}; 58 | } 59 | 60 | if(typeof(async) == 'undefined') { 61 | async = true; 62 | } 63 | 64 | if(typeof(postData) == 'undefined') { 65 | postData = null; 66 | } 67 | 68 | if (method.toLowerCase() == 'get' && postData) { 69 | var queryString = encodeData(postData); 70 | if(queryString) { 71 | url += ((url.indexOf('?') == -1) ? '?' : '&') + queryString; 72 | } 73 | } 74 | 75 | var xhr = getRequest(); 76 | if (xhr === null) { 77 | throw new Error('XMLHttpRequest not supported'); 78 | } 79 | 80 | xhr.onreadystatechange = function() { 81 | if (xhr.readyState != 4) { 82 | return; // request is not finished yet 83 | } 84 | 85 | /* 86 | * When request is finised, run appropriate callback functions (if 87 | * any). Callbacks are selected by the response's status code. 88 | * (see HTTP/1.1 Status Code Definitions: 89 | * http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html) 90 | */ 91 | 92 | if(xhr.status == 200) { 93 | if (callbacks.success) { 94 | // X-JSON is Prototype-specific. Without Prototype, we parse it here. 95 | // NOTE: In Safari, the header is X-Json. In Firefox, IE, and Opera the header is X-JSON. 96 | var xJson = null; 97 | var headers = xhr.getAllResponseHeaders().split('\n'); 98 | 99 | for(var i = 0 ; i < headers.length; i++ ) { 100 | if(headers[i].indexOf('X-JSON') != -1 || headers[i].indexOf('X-Json') != -1) { 101 | xJson = headers[i].replace('X-JSON: ', ''); 102 | xJson = xJson.replace('X-Json: ', ''); 103 | } 104 | } 105 | 106 | var json = parseJSON(xJson) || parseJSON(xhr.responseText); 107 | if (json && json.stat==="fail") { 108 | if (callbacks.failure) { 109 | callbacks.failure(json.err.code, json.err.msg); 110 | } else { 111 | alert(json.err.msg); 112 | } 113 | } else { // success 114 | if (xhr.responseText.length>1) { 115 | json = parseJSON(xhr.responseText); 116 | } 117 | callbacks.success(json); 118 | } 119 | } 120 | } else if(xhr.status == 400 || xhr.status == 403 || xhr.status == 500) { 121 | if(callbacks.failure) { 122 | callbacks.failure(xhr.status, xhr.responseText); 123 | } else { 124 | alert(xhr.statusText); 125 | } 126 | } 127 | }; // onreadystatechange 128 | 129 | xhr.open(method.toUpperCase(), url, async); 130 | 131 | if (method == 'post') { 132 | xhr.setRequestHeader("Content-type", "application/x-www-form-urlencoded"); 133 | } 134 | 135 | xhr.send(encodeData(postData)); 136 | }; 137 | -------------------------------------------------------------------------------- /Pesquisa/Writing a compiler using Python, Lex, Yacc and LLVM by Alcides Fonseca_arquivos/reply_data/quant.js: -------------------------------------------------------------------------------- 1 | // 2 | // For correct measurement, DO NOT HOST THIS FROM ANOTHER SERVER 3 | // 4 | function _qcdst(){if(_qctzoff(0)!=_qctzoff(6))return 1;return 0;} 5 | function _qctzoff(m){ 6 | var d1=new Date(2000,m,1,0,0,0,0); 7 | var t=d1.toGMTString(); 8 | var d3=new Date(t.substring(0,t.lastIndexOf(" ")-1)); 9 | return d1-d3; 10 | } 11 | function _qceuc(s){ 12 | if(typeof(encodeURIComponent)=='function'){return encodeURIComponent(s);} 13 | else{return escape(s);} 14 | } 15 | function _qcrnd(){return Math.round(Math.random()*2147483647);} 16 | function _qcgc(n){ 17 | var v=''; 18 | var c=document.cookie;if(!c)return v; 19 | var i=c.indexOf(n+"="); 20 | var len=i+n.length+1; 21 | if(i>-1){ 22 | var end=c.indexOf(";", len); 23 | if(end<0)end=c.length; 24 | v=c.substring(len,end); 25 | } 26 | return v; 27 | } 28 | function _qcdomain(){ 29 | var d=document.domain; 30 | if(d.substring(0,4)=="www.")d=d.substring(4,d.length); 31 | var a=d.split(".");var len=a.length; 32 | if(len<3)return d; 33 | var e=a[len-1]; 34 | if(e.length<3)return d; 35 | d=a[len-2]+"."+a[len-1]; 36 | return d; 37 | } 38 | function _qcsc(m){ 39 | var s="";var d=_qcdomain(); 40 | if (m=="ad"||d=="doubleclick.net"||d=="atdmt.com"||d=="yieldmanager.com"||d=="fimserve.com"|| 41 | d=="tribalfusion.com"||d=="trafficmp.com"){s+=";fpan=u;fpa=";return s;} 42 | var u=document;var a=_qcgc("__qca"); 43 | if(a.length>0){s+=";fpan=0;fpa="+a;} 44 | else{ 45 | var da=new Date(); 46 | a='P0-'+_qcrnd()+'-'+da.getTime(); 47 | u.cookie="__qca="+a+"; expires=Sun, 18 Jan 2038 00:00:00 GMT; path=/; domain="+d; 48 | a=_qcgc("__qca"); 49 | if(a.length>0){s+=";fpan=1;fpa="+a;} 50 | else{s+=";fpan=u;fpa=";} 51 | } 52 | return s; 53 | } 54 | function _qcdc(n){ 55 | document.cookie=n+"=; expires=Thu, 01 Jan 1970 00:00:01 GMT; path=/; domain="+_qcdomain(); 56 | } 57 | function _qpxload(){ 58 | if((_qimg)&& typeof _qimg.width =="number"){ 59 | if (_qimg.width==3){_qcdc("__qca");} 60 | }} 61 | function quantserve(){ 62 | var r=_qcrnd(); 63 | var sr='',qo='',qm='',url='',ref='',je='u',ns='1',media='webpage',event='load'; 64 | if(typeof _qoptions !="undefined" && _qoptions!=null){ 65 | for(var k in _qoptions){ 66 | if(typeof(_qoptions[k])!='string'){continue;} 67 | if(k=='qacct'){_qacct=_qoptions[k];} 68 | else{qo+=';'+k+'='+_qceuc(_qoptions[k]);} 69 | if(k=='media'){media=_qoptions[k];} 70 | if(k=='event'){event=_qoptions[k];} 71 | } 72 | _qoptions=null; 73 | } 74 | if((typeof _qacct =="undefined")||(_qacct.length==0))return; 75 | if(media=='webpage' && event=='load'){ 76 | if((typeof _qpixelsent !="undefined")&&(_qpixelsent==_qacct))return; 77 | _qpixelsent=_qacct;} 78 | var ce=(navigator.cookieEnabled)?"1":"0"; 79 | if(typeof navigator.javaEnabled !='undefined')je=(navigator.javaEnabled())?"1":"0"; 80 | if(typeof _qmeta !="undefined" && _qmeta!=null){qm=';m='+_qceuc(_qmeta);_qmeta=null;} 81 | if(self.screen){sr=screen.width+"x"+screen.height+"x"+screen.colorDepth;} 82 | var d=new Date(); 83 | var dst=_qcdst(); 84 | 85 | 86 | 87 | 88 | 89 | 90 | var dg="E10860-W-MO-5"; 91 | var qs="http://pixel.quantserve.com"; 92 | var fp=_qcsc(media); 93 | if(window.location && window.location.href)url=_qceuc(window.location.href); 94 | if(window.document && window.document.referrer)ref=_qceuc(window.document.referrer); 95 | if(self==top)ns='0'; 96 | _qimg=new Image(); 97 | _qimg.alt=""; 98 | _qimg.src=qs+'/pixel'+';r='+r+fp+';ns='+ns+';url='+url+';ref='+ref+';ce='+ce+';je='+je+';sr='+sr+';dg='+dg+';dst='+dst+';et='+d.getTime()+';tzo='+d.getTimezoneOffset()+';a='+_qacct+qo+qm; 99 | _qimg.onload=function() {_qpxload();} 100 | } 101 | quantserve(); 102 | -------------------------------------------------------------------------------- /Pesquisa/Writing a compiler using Python, Lex, Yacc and LLVM by Alcides Fonseca_arquivos/styles.css: -------------------------------------------------------------------------------- 1 | #dsq-content iframe, #dsq-popup-alert iframe { 2 | height: 355px; 3 | } 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | /* 13 | * Narcissus theme customization 14 | */ 15 | #dsq-content .dsq-header-avatar img { 16 | width: 48px; 17 | height: 48px; 18 | } 19 | 20 | 21 | 22 | -------------------------------------------------------------------------------- /Pesquisa/Writing a compiler using Python, Lex, Yacc and LLVM by Alcides Fonseca_arquivos/syntax.css: -------------------------------------------------------------------------------- 1 | .highlight .hll { background-color: #ffffcc } 2 |
.highlight { background: #f8f8f8; }
.highlight .c { color: #408080; font-style: italic } /* Comment */
.highlight .err { border: 1px solid #FF0000 } /* Error */
.highlight .k { color: #008000; font-weight: bold } /* Keyword */
.highlight .o { color: #666666 } /* Operator */
.highlight .cm { color: #408080; font-style: italic } /* Comment.Multiline */
.highlight .cp { color: #BC7A00 } /* Comment.Preproc */
.highlight .c1 { color: #408080; font-style: italic } /* Comment.Single */
.highlight .cs { color: #408080; font-style: italic } /* Comment.Special */
.highlight .gd { color: #A00000 } /* Generic.Deleted */
.highlight .ge { font-style: italic } /* Generic.Emph */
.highlight .gr { color: #FF0000 } /* Generic.Error */
.highlight .gh { color: #000080; font-weight: bold } /* Generic.Heading */
.highlight .gi { color: #00A000 } /* Generic.Inserted */
.highlight .go { color: #808080 } /* Generic.Output */
.highlight .gp { color: #000080; font-weight: bold } /* Generic.Prompt */
.highlight .gs { font-weight: bold } /* Generic.Strong */
.highlight .gu { color: #800080; font-weight: bold } /* Generic.Subheading */
.highlight .gt { color: #0040D0 } /* Generic.Traceback */
.highlight .kc { color: #008000; font-weight: bold } /* Keyword.Constant */
.highlight .kd { color: #008000; font-weight: bold } /* Keyword.Declaration */
.highlight .kn { color: #008000; font-weight: bold } /* Keyword.Namespace */
.highlight .kp { color: #008000 } /* Keyword.Pseudo */
.highlight .kr { color: #008000; font-weight: bold } /* Keyword.Reserved */
.highlight .kt { color: #B00040 } /* Keyword.Type */
.highlight .m { color: #666666 } /* Literal.Number */
.highlight .s { color: #BA2121 } /* Literal.String */
.highlight .na { color: #7D9029 } /* Name.Attribute */
.highlight .nb { color: #008000 } /* Name.Builtin */
.highlight .nc { color: #0000FF; font-weight: bold } /* Name.Class */
.highlight .no { color: #880000 } /* Name.Constant */
.highlight .nd { color: #AA22FF } /* Name.Decorator */
.highlight .ni { color: #999999; font-weight: bold } /* Name.Entity */
.highlight .ne { color: #D2413A; font-weight: bold } /* Name.Exception */
.highlight .nf { color: #0000FF } /* Name.Function */
.highlight .nl { color: #A0A000 } /* Name.Label */
.highlight .nn { color: #0000FF; font-weight: bold } /* Name.Namespace */
.highlight .nt { color: #008000; font-weight: bold } /* Name.Tag */
.highlight .nv { color: #19177C } /* Name.Variable */
.highlight .ow { color: #AA22FF; font-weight: bold } /* Operator.Word */
.highlight .w { color: #bbbbbb } /* Text.Whitespace */
.highlight .mf { color: #666666 } /* Literal.Number.Float */
.highlight .mh { color: #666666 } /* Literal.Number.Hex */
.highlight .mi { color: #666666 } /* Literal.Number.Integer */
.highlight .mo { color: #666666 } /* Literal.Number.Oct */
.highlight .sb { color: #BA2121 } /* Literal.String.Backtick */
.highlight .sc { color: #BA2121 } /* Literal.String.Char */
.highlight .sd { color: #BA2121; font-style: italic } /* Literal.String.Doc */
.highlight .s2 { color: #BA2121 } /* Literal.String.Double */
.highlight .se { color: #BB6622; font-weight: bold } /* Literal.String.Escape */
.highlight .sh { color: #BA2121 } /* Literal.String.Heredoc */
.highlight .si { color: #BB6688; font-weight: bold } /* Literal.String.Interpol */
.highlight .sx { color: #008000 } /* Literal.String.Other */
.highlight .sr { color: #BB6688 } /* Literal.String.Regex */
.highlight .s1 { color: #BA2121 } /* Literal.String.Single */
.highlight .ss { color: #19177C } /* Literal.String.Symbol */
.highlight .bp { color: #008000 } /* Name.Builtin.Pseudo */
.highlight .vc { color: #19177C } /* Name.Variable.Class */
.highlight .vg { color: #19177C } /* Name.Variable.Global */
.highlight .vi { color: #19177C } /* Name.Variable.Instance */
.highlight .il { color: #666666 } /* Literal.Number.Integer.Long */ -------------------------------------------------------------------------------- /Pesquisa/Writing a compiler using Python, Lex, Yacc and LLVM by Alcides Fonseca_arquivos/twitter.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wanderlan/llvm-pascal/19fda52906749ee0bd05d0e0c1d81d2806b7d263/Pesquisa/Writing a compiler using Python, Lex, Yacc and LLVM by Alcides Fonseca_arquivos/twitter.png -------------------------------------------------------------------------------- /Pesquisa/Writing a compiler using Python, Lex, Yacc and LLVM by Alcides Fonseca_arquivos/twitterProfilePhoto_normal.xml: -------------------------------------------------------------------------------- 1 | 2 | AccessDeniedAccess Denied67BDEEA33934E44DoIzO7ljABvx9pBpkcqk6koFv6tB8eXyjNiI8cLLVhR/ZoxXZmKn2NkSOoho2/hRM -------------------------------------------------------------------------------- /Pesquisa/Writing a compiler using Python, Lex, Yacc and LLVM by Alcides Fonseca_arquivos/twitter_002.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wanderlan/llvm-pascal/19fda52906749ee0bd05d0e0c1d81d2806b7d263/Pesquisa/Writing a compiler using Python, Lex, Yacc and LLVM by Alcides Fonseca_arquivos/twitter_002.png -------------------------------------------------------------------------------- /Pesquisa/WritingYourCompilerUsingLLVM_arquivos/134242.js: -------------------------------------------------------------------------------- 1 | var clicky={init:function(site_id){clicky.pageview_fired=0;if(document.location.protocol=="https:"){clicky.domain="https://in.getclicky.com";clicky.secure=1;}else{clicky.domain="http://in.getclicky.com";clicky.secure=0;}clicky.base=clicky.domain+"/in.php?site_id="+site_id+"&res="+screen.width+"x"+screen.height+"&lang="+(navigator.language||navigator.browserLanguage||'en').substr(0,2)+"&secure="+clicky.secure;if(clicky_custom.session){for(var i in clicky_custom.session){clicky.base+="&custom["+clicky.enc(i)+"]="+clicky.enc(clicky_custom.session[i]);}}if(clicky_custom.goal){for(var i in clicky_custom.goal){clicky.base+="&goal["+clicky.enc(i)+"]="+clicky.enc(clicky_custom.goal[i]);}}if(clicky_custom.async){clicky.advanced();}else clicky.add_event(window,'load',clicky.advanced);clicky.ref=RegExp("^https?://[^/]*"+location.host.replace(/^www\./i,"")+"/","i").test(document.referrer)?"":clicky.enc(document.referrer);if(!clicky_custom.pageview_disable)clicky.pageview();},beacon:function(x){var s=document.createElement('script');s.type='text/javascript';s.async=true;s.src=clicky.base+x+'&mime=js&x='+Math.random();(document.getElementsByTagName('head')[0]||document.getElementsByTagName('body')[0]).appendChild(s);clicky.ref="";},pageview:function(){if(clicky.pageview_fired)return;clicky.pageview_fired=1;if(location.hash.match(/utm_/i)){var href=location.pathname+(location.search?location.search+'&':'?')+location.hash.substr(1);}else{var href=location.pathname+location.search;}clicky.beacon("&href="+clicky.enc(clicky_custom.href||href)+"&title="+clicky.enc(clicky_custom.title||document.title)+"&ref="+clicky.ref);},log:function(href,title,type){type=type||"click";if(type=="pageview")href=href.replace(/^https?:\/\/([^\/]+)/i,"");clicky.beacon("&type="+type+"&title="+clicky.enc(title)+"&href="+clicky.enc(href)+"&ref="+clicky.ref);if(type=="download"||type=="outbound")clicky.pause();},pause:function(x){var now=new Date();var stop=now.getTime()+(x||clicky_custom.timer||500);while(now.getTime()=c)return 0;b/=c;b=Math.log((1-b)/b);return d*(b+6)/12};a.computeCircle_=function(b,d){b=Math.sqrt(Math.pow(d,2)-Math.pow(b,2));return isNaN(b)?0:b}; 4 | a.addStyleRule_=function(b,d){if(AdSenseGraphics.IS_IE_)document.styleSheets[0].addRule(b,d);else{var c=document.createElement("style");c.type="text/css";var e=AdSenseGraphics.IS_SAFARI_?"innerText":"innerHTML";c[e]=b+"{"+d+"}";b=document.getElementsByTagName("head")[0];b.appendChild(c)}}; 5 | a.createDiv_=function(b,d,c,e,f){var h=document.createElement("div"),j="position:absolute;overflow:hidden;left:";j+=b;j+="px;top:";j+=d;j+="px;width:";j+=c;j+="px;height:";j+=e;j+="px;";if(f!=null){j+="opacity:";j+=f;if(AdSenseGraphics.IS_IE_){j+=";filter: alpha(opacity=";j+=Math.round(f*100);j+=");"}}h.style.cssText=j;return h}; 6 | a.getCirclePixelIntercepts_=function(b,d,c){var e=new Array(4);e[AdSenseGraphics.Y_INTERCEPT_LEFT_]=this.computeCircle_(this.getPixelLeftX_(b),c);e[AdSenseGraphics.Y_INTERCEPT_RIGHT_]=this.computeCircle_(this.getPixelRightX_(b),c);e[AdSenseGraphics.X_INTERCEPT_BOTTOM_]=this.computeCircle_(this.getPixelBottomY_(d),c);e[AdSenseGraphics.X_INTERCEPT_TOP_]=this.computeCircle_(this.getPixelTopY_(d),c);return e}; 7 | a.getSigmoidPixelIntercepts_=function(b,d,c,e){var f=new Array(4);f[AdSenseGraphics.Y_INTERCEPT_LEFT_]=this.computeSigmoid_(this.getPixelLeftX_(b),c,e);f[AdSenseGraphics.Y_INTERCEPT_RIGHT_]=this.computeSigmoid_(this.getPixelRightX_(b),c,e);f[AdSenseGraphics.X_INTERCEPT_BOTTOM_]=this.computeSigmoidInverse_(this.getPixelBottomY_(d),c,e);f[AdSenseGraphics.X_INTERCEPT_TOP_]=this.computeSigmoidInverse_(this.getPixelTopY_(d),c,e);return f}; 8 | a.getSigmoidAntiAliasOpacity_=function(b,d,c,e){c=this.getSigmoidPixelIntercepts_(b,d,c,e);b=this.getAntiAliasOpacity_(b,d,c);return b==-1?0:b};a.getCircleAntiAliasOpacity_=function(b,d,c,e){c=this.getCirclePixelIntercepts_(b,d,c);b=this.getAntiAliasOpacity_(b,d,c);if(b==-1)return 0;return e?1-b:b}; 9 | a.getAntiAliasOpacity_=function(b,d,c){var e=0,f=new Array(2),h=new Array(2),j=false,m=false,g=false,n=false,k=this.getPixelBottomY_(d);d=this.getPixelTopY_(d);var l=this.getPixelLeftX_(b);b=this.getPixelRightX_(b);if(c[AdSenseGraphics.Y_INTERCEPT_LEFT_]>=k&&c[AdSenseGraphics.Y_INTERCEPT_LEFT_]=l&&c[AdSenseGraphics.X_INTERCEPT_TOP_]=k&&c[AdSenseGraphics.Y_INTERCEPT_RIGHT_]=l&&c[AdSenseGraphics.X_INTERCEPT_BOTTOM_]h[1]?h[0]:h[1];e=f+(h-f)/2}else if(j&&n)e=h[0]*f[1]/2;else if(m&&g)e=1-(1-f[0])*(1-h[1])/2;else if(m&&n){h=f[0]<=f[1]?f[0]:f[1];f=f[0]>f[1]?f[0]:f[1];e= 11 | h+(f-h)/2}return e}; 12 | a.createSigmoidCurve=function(b,d,c,e,f,h){this.addStyleRule_("#"+b.id+" ."+AdSenseGraphics.S_CURVE_CLASS_NAME_+" div","background-color: "+e);b.style.display="none";e=this.createDiv_(0,0,d,c);e.className=AdSenseGraphics.S_CURVE_CLASS_NAME_;for(var j,m=c-1,g,n,k,l=c-1,q=0;q0){var l=n?d-k:0;k=this.createDiv_(l,0,k,c-h);l=k.style;l.backgroundColor=e;m?(l.borderTop=f):(l.borderBottom=f);b.appendChild(k)}k=c-j;if(k>0){l=m?c-k:0;k=this.createDiv_(0,l,d-h,k);l=k.style;l.backgroundColor=e;n?(l.borderLeft=f):(l.borderRight=f);b.appendChild(k)}this.createRoundedCorner_(b,d,c,j,h,n,m);g.display=""}; 16 | a.createRoundedCorner_=function(b,d,c,e,f,h,j){var m=f>0;f=e-f;d=h?0:d-e;var g=j?0:c-e;c=this.createDiv_(d,g,e,e);c.className=AdSenseGraphics.ROUNDED_CORNER_BG_CLASS_NAME_;var n=this.createDiv_(d,g,e,e);n.className=m?AdSenseGraphics.ROUNDED_CORNER_BORDER_CLASS_NAME_:AdSenseGraphics.ROUNDED_CORNER_BG_CLASS_NAME_;for(var k=f,l=e,q=f,o=e,s,t,u=e-1,r=0;r0){g=j?e-s-l:s;g=this.createDiv_(d,g,1,l);n.appendChild(g)}for(p=q-1;p0?a.token:null;for(var b=0;b0)this.aa();else if(a==1&&(this.j||this.c0||a==1&&(this.j||this.c0){h(this.b,this.b.k);this.o[2][o].display=="none"&&this.L(0)}else{h(this.b,null);this.M(0)}if(this.j||this.c").addClass('twitterapplist').appendTo('.twitterapp'); 4 | $.getJSON("/twitterfeed.html", 5 | function(data) { 6 | $('.twitterapp').removeClass('loading'); 7 | var num = 0; 8 | $.each(data, function(i, item) { 9 | if (item.text[0] == "@") return; 10 | $("
  • ").html(twitterStatus(item)).appendTo(".twitterapplist"); 11 | if (num++ == 5) return false; 12 | }); 13 | if ($('#content').height() < $('#nav').height()) { 14 | if (!$('#wrapper').hasClass('wide')) { 15 | $('#wrapper').css('background', '#fff'); 16 | } 17 | } 18 | }); 19 | 20 | 21 | } 22 | 23 | function twitterStatus(item) { 24 | var text = item.text; 25 | text = text.replace(/(https?:\/\/[^ ,!;?]+)(?:[,.!;\)\]-](\s|$)|$)/g, "$1$2"); 26 | text = text.replace(/#([^ ,!;?]+)\b/g, "#$1"); 27 | text = text.replace(/@([^ ,!;?]+)\b/g, "@$1"); 28 | text = text + " " + twitterSince(item) + " | link"; 29 | return text; 30 | } 31 | 32 | function twitterSince(item) { 33 | var now = new Date(); 34 | var date = Date.parse(item.created_at); 35 | var diff = parseInt(now.getTime() / 1000) - parseInt(date / 1000); 36 | var time = ""; 37 | if (diff >= 86400) { 38 | time = parseInt(diff / 86400.0) + "d"; 39 | } 40 | else if (diff >= 3600) { 41 | time = parseInt(diff / 3600.0) + "h"; 42 | } 43 | else if (diff >= 60) { 44 | time = parseInt(diff / 60.0) + "m"; 45 | } 46 | else { 47 | time = diff + "s"; 48 | } 49 | return time + " ago"; 50 | } 51 | 52 | $(startTwitter); 53 | -------------------------------------------------------------------------------- /Pesquisa/d-pldi06.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wanderlan/llvm-pascal/19fda52906749ee0bd05d0e0c1d81d2806b7d263/Pesquisa/d-pldi06.pdf -------------------------------------------------------------------------------- /Pesquisa/tcc-eduardo-mello-cantu_v2.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wanderlan/llvm-pascal/19fda52906749ee0bd05d0e0c1d81d2806b7d263/Pesquisa/tcc-eduardo-mello-cantu_v2.pdf -------------------------------------------------------------------------------- /SymbolTable.pas: -------------------------------------------------------------------------------- 1 | unit SymbolTable; 2 | 3 | interface 4 | 5 | uses 6 | Contnrs, Token, Scanner; 7 | 8 | const 9 | TABLE_SIZE = 98317; // 49157; 6151; 196613; 393241 10 | 11 | type 12 | TSymbolTable = class 13 | private 14 | Table : array[0..TABLE_SIZE - 1] of TToken; 15 | Stack : TStack; 16 | Current : Integer; 17 | Scope : Word; 18 | function Hash(const S : string) : Cardinal; 19 | public 20 | constructor Create; 21 | destructor Destroy; override; 22 | function GetHash(Name : string) : Cardinal; 23 | function Get(Name : string) : TToken; 24 | function Count : Integer; 25 | procedure Add(Token : TToken); 26 | procedure Delete(Token : TToken); 27 | procedure PushScope; 28 | procedure PopScope; 29 | function Last : TToken; 30 | function Previous : TToken; 31 | property Tokens[Name : string] : TToken read Get; default; 32 | end; 33 | 34 | implementation 35 | 36 | uses 37 | CompilerUtils; 38 | 39 | {$R-,O-} 40 | function TSymbolTable.Hash(const S : string) : Cardinal; 41 | var // Jenkins 42 | I : Cardinal; 43 | begin 44 | Result := 0; 45 | for I := 1 to Length(S) do begin 46 | inc(Result, (Result + ord(UpCase(S[I]))) shl 10); 47 | Result := Result xor (Result shr 6); 48 | end; 49 | inc(Result, Result shl 3); 50 | Result := Result xor (Result shr 11); 51 | Result := ((Result + (Result shl 15)) + ord(S[length(S)]) * 2) mod TABLE_SIZE; 52 | end; 53 | {$R+,O+} 54 | 55 | function TSymbolTable.GetHash(Name : string) : Cardinal; begin 56 | Result := Hash(Name); 57 | while (Table[Result] <> nil) and (LowerCase(Table[Result].Lexeme) <> LowerCase(Name)) do 58 | Result := (Result + 1) mod TABLE_SIZE; 59 | end; 60 | 61 | function TSymbolTable.Get(Name : string) : TToken; begin 62 | Result := Table[GetHash(Name)]; 63 | end; 64 | 65 | function TSymbolTable.Count : Integer; begin 66 | Result := Stack.Count - 1 - Scope; 67 | end; 68 | 69 | constructor TSymbolTable.Create; begin 70 | Stack := TStack.Create; 71 | Stack.Push(nil); 72 | end; 73 | 74 | destructor TSymbolTable.Destroy; begin 75 | while Stack.Count <> 0 do TToken(Stack.Pop).Free; 76 | Stack.Free; 77 | inherited; 78 | end; 79 | 80 | {$R-,O-} 81 | procedure TSymbolTable.Add(Token : TToken); 82 | var 83 | H : Cardinal; 84 | begin 85 | if Count >= TABLE_SIZE then raise EFatal.Create('Symbol table is full'); 86 | H := Hash(Token.Lexeme); 87 | Token.Scope := Scope; 88 | while Table[H] <> nil do 89 | if LowerCase(Table[H].Lexeme) = LowerCase(Token.Lexeme) then begin 90 | if Table[H].Scope = Token.Scope then 91 | raise EError.CreateFmt('Identifier redeclared "%s"', [Token.Lexeme]) 92 | else 93 | Token.NextScope := Table[H]; 94 | break; 95 | end 96 | else 97 | H := (H + 1) mod TABLE_SIZE; 98 | Token.Hash := H; 99 | Table[H] := Token; 100 | Stack.Push(Token); 101 | end; 102 | {$R+,O+} 103 | 104 | procedure TSymbolTable.Delete(Token : TToken); 105 | var 106 | H : Cardinal; 107 | begin 108 | H := Token.Hash; 109 | if (H >= TABLE_SIZE) or (Table[H] = nil) or 110 | (LowerCase(Table[H].Lexeme) <> LowerCase(Token.Lexeme)) then 111 | raise EFatal.CreateFmt('Trying to delete invalid token "%s", possibly data corruption', [Token.Lexeme]) 112 | else 113 | Table[H] := Table[H].NextScope; 114 | Token.Free; 115 | end; 116 | 117 | procedure TSymbolTable.PushScope; begin 118 | inc(Scope); 119 | Stack.Push(nil); 120 | end; 121 | 122 | procedure TSymbolTable.PopScope; begin 123 | while Stack.Peek <> nil do Delete(TToken(Stack.Pop)); 124 | Stack.Pop; 125 | if Scope > 0 then dec(Scope); 126 | end; 127 | 128 | function TSymbolTable.Last : TToken; begin 129 | Current := Stack.Count - 1; 130 | Result := Stack.Peek; 131 | end; 132 | 133 | type 134 | THackStack = class(TStack); 135 | 136 | function TSymbolTable.Previous : TToken; begin 137 | if Current >= 0 then begin 138 | if THackStack(Stack).List[Current] <> nil then dec(Current); 139 | Result := THackStack(Stack).List[Current]; 140 | end 141 | else 142 | Result := nil; 143 | end; 144 | 145 | end. 146 | -------------------------------------------------------------------------------- /TestSuite/Test01.pas: -------------------------------------------------------------------------------- 1 | unit Test01; 2 | 3 | interface 4 | 5 | implementation 6 | 7 | uses 8 | Classes; 9 | 10 | procedure PrTest01; 11 | var 12 | A: TStrings; 13 | begin 14 | with A as TStringList do 15 | begin 16 | end; 17 | end; 18 | 19 | end. 20 | -------------------------------------------------------------------------------- /TestSuite/Test02.pas: -------------------------------------------------------------------------------- 1 | unit Test02; 2 | 3 | interface 4 | 5 | uses 6 | Messages; 7 | 8 | type 9 | TTest02 = class 10 | public 11 | procedure WMEraseBkgnd(var Message: TWMEraseBkgnd); message WM_ERASEBKGND; 12 | end; 13 | 14 | implementation 15 | 16 | { TFoo } 17 | 18 | procedure TTest02.WMEraseBkgnd(var Message: TWMEraseBkgnd); 19 | begin 20 | end; 21 | 22 | end. 23 | -------------------------------------------------------------------------------- /TestSuite/Test03.pas: -------------------------------------------------------------------------------- 1 | unit Test03; 2 | 3 | interface 4 | 5 | type 6 | (*$IFDEF mswindowsx *) 7 | erro=dd; 8 | (*$ELSE *) 9 | erro=integer; 10 | (*$ENDIF *) 11 | 12 | implementation 13 | 14 | end. 15 | 16 | -------------------------------------------------------------------------------- /TestSuite/Test04.pas: -------------------------------------------------------------------------------- 1 | unit Test04; 2 | 3 | interface 4 | 5 | {$ifndef ver110} 6 | 7 | {$ifndef ver90} 8 | {$ifndef ver100} 9 | {$define UseInt64} 10 | {$endif} 11 | {$endif} 12 | 13 | 14 | {$ifdef UseInt64} 15 | type TInt64 = Int64; 16 | {$else} 17 | type TInt64 = Comp; 18 | {$endif} 19 | 20 | {$else} 21 | 22 | type TInt64 = TLargeInteger; 23 | 24 | {$endif} 25 | 26 | implementation 27 | 28 | end. 29 | -------------------------------------------------------------------------------- /TestSuite/Test05.pas: -------------------------------------------------------------------------------- 1 | unit Test05; 2 | 3 | interface 4 | 5 | function FnTest05: Integer; 6 | 7 | implementation 8 | 9 | function FnTest05; 10 | begin 11 | Result := 0; 12 | end; 13 | 14 | end. 15 | -------------------------------------------------------------------------------- /TestSuite/Test06.pas: -------------------------------------------------------------------------------- 1 | program Test06; 2 | var 3 | S : string; 4 | begin 5 | S := '''ABC''abcd''asas'; 6 | S := #13#10''''; 7 | S := #39'ABC'#39; 8 | S := #39+'ABC'#39; 9 | S := #39'ABC'+#39; 10 | S := 'A'#13#10'B'#13#10'C'; 11 | S := 'A'#$A'B'; 12 | end. 13 | -------------------------------------------------------------------------------- /TestSuite/Test07.pas: -------------------------------------------------------------------------------- 1 | unit Test07; 2 | 3 | interface 4 | 5 | procedure FnTest07; stdcall; external 'test07.dll'; 6 | 7 | implementation 8 | 9 | end. 10 | -------------------------------------------------------------------------------- /TestSuite/Test08.pas: -------------------------------------------------------------------------------- 1 | unit Test08; 2 | 3 | interface 4 | 5 | type 6 | tyTest08 = (ttA, ttB, ttC); 7 | var 8 | vaTest08: set of Ord(ttA)..Ord(ttC); 9 | 10 | implementation 11 | 12 | end. 13 | -------------------------------------------------------------------------------- /TestSuite/Test09.pas: -------------------------------------------------------------------------------- 1 | unit Test09; 2 | 3 | interface 4 | 5 | implementation 6 | 7 | procedure PrTeste09; 8 | label lbSaida; 9 | begin 10 | goto lbSaida; 11 | lbSaida: 12 | end; 13 | 14 | end. 15 | -------------------------------------------------------------------------------- /TestSuite/Test10.pas: -------------------------------------------------------------------------------- 1 | unit Test10; 2 | 3 | interface 4 | 5 | implementation 6 | 7 | procedure PrTest10A(a: string = ''); 8 | begin 9 | 10 | end; 11 | 12 | procedure PrTest10B; 13 | begin 14 | PrTest10A('', ); // Erro no compilador Delphi. LLVM-Pascal pega este erro. 15 | end; 16 | 17 | end. 18 | -------------------------------------------------------------------------------- /TestSuite/Test11.pas: -------------------------------------------------------------------------------- 1 | unit Test11; 2 | 3 | interface 4 | 5 | type 6 | tyTest11 = ( ttTest11A = 1, ttTest11B = 2 ); 7 | 8 | var 9 | A, B : string = 'x'; 10 | 11 | implementation 12 | 13 | end. 14 | -------------------------------------------------------------------------------- /TestSuite/Test12.pas: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wanderlan/llvm-pascal/19fda52906749ee0bd05d0e0c1d81d2806b7d263/TestSuite/Test12.pas -------------------------------------------------------------------------------- /TestSuite/Test13.pas: -------------------------------------------------------------------------------- 1 | unit Test13; 2 | 3 | interface 4 | 5 | threadvar 6 | tvTest13: Integer; 7 | 8 | implementation 9 | 10 | end. 11 | -------------------------------------------------------------------------------- /TestSuite/Test14.pas: -------------------------------------------------------------------------------- 1 | unit Test14; 2 | 3 | interface 4 | 5 | type 6 | TTest14 = class 7 | private 8 | FTest14: Integer; 9 | public 10 | property Tst14: Integer index -1 read FTest14 write FTest14; 11 | end; 12 | 13 | implementation 14 | 15 | end. 16 | -------------------------------------------------------------------------------- /TestSuite/Test15.pas: -------------------------------------------------------------------------------- 1 | program Test15; 2 | 3 | const 4 | X = %date; 5 | type 6 | [Teste] 7 | C = record 8 | var 9 | s:integer;//=1; 10 | type t = integer; 11 | [Teste] 12 | cc= class 13 | y:integer; 14 | end; 15 | [Teste] 16 | [Teste.abc(123, 'asas')] 17 | property X : integer; 18 | procedure x3; final; 19 | end; 20 | 21 | type 22 | TPair = class // TKey and TValue are type parameters 23 | FKey: TKey; 24 | FValue: TValue; 25 | function GetValue: TValue; 26 | end; 27 | 28 | function TPair.GetValue: TValue; 29 | begin 30 | Result := FValue; 31 | end; 32 | 33 | type 34 | TFoo = class 35 | FData: T; 36 | end; 37 | 38 | var 39 | F: TFoo; // 'Integer' is the type argument of TFoo 40 | 41 | type 42 | TMyProc2 = procedure(Param1, Param2: Y) of object; 43 | 44 | TFoo = class 45 | procedure Test; 46 | procedure MyProc2(X, Y: T); 47 | end; 48 | 49 | type 50 | TFoo = class 51 | type 52 | TBar = class 53 | X: Integer; 54 | // ... 55 | end; 56 | // ... 57 | TBaz = class 58 | type 59 | TQux = class 60 | X: Integer; 61 | // ... 62 | end; 63 | // ... 64 | end; 65 | end; 66 | var 67 | N: TFoo.TBar; 68 | 69 | type 70 | TOuter = class 71 | type 72 | TData = class 73 | FFoo1: TFoo; // declared with closed constructed type 74 | FFoo2: TFoo; // declared with open constructed type 75 | FFooBar1: TFoo.TBar; // declared with closed constructed type 76 | FFooBar2: TFoo.TBar; // declared with open constructed type 77 | FBazQux1: TBaz.TQux; // declared with closed constructed type 78 | FBazQux2: TBaz.TQux; // declared with open constructed type 79 | end; 80 | var 81 | FIntegerData: TData; 82 | FStringData: TData; 83 | end; 84 | 85 | type 86 | TFoo1 = class(TBar) // Actual type 87 | end; 88 | 89 | TFoo2 = class(TBar2) // Open constructed type 90 | end; 91 | TFoo3 = class(TBar3) // Closed constructed type 92 | end; 93 | 94 | type 95 | TRecord = record 96 | FData: T; 97 | end; 98 | 99 | type 100 | IAncestor = interface 101 | function GetRecord: TRecord; 102 | end; 103 | 104 | IFoo = interface(IAncestor) 105 | procedure AMethod(Param: T); 106 | end; 107 | 108 | type 109 | TFoo = class(TObject, IFoo) 110 | FField: TRecord; 111 | procedure AMethod(Param: T); 112 | function GetRecord: TRecord; 113 | end; 114 | 115 | type 116 | TMyProc = procedure(Param: T); 117 | TMyProc2 = procedure(Param1, Param2: Y) of object; 118 | type 119 | TFoo = class 120 | procedure Test; 121 | procedure MyProc(X, Y: Integer); 122 | end; 123 | 124 | procedure Sample(Param: Integer); 125 | begin 126 | Writeln(Param); 127 | end; 128 | 129 | procedure TFoo.MyProc(X, Y: Integer); 130 | begin 131 | Writeln('X:', X, ', Y:', Y); 132 | end; 133 | 134 | procedure TFoo.Test; 135 | var 136 | X: TMyProc; 137 | Y: TMyProc2; 138 | begin 139 | X := Sample; 140 | X(10); 141 | Y := MyProc; 142 | Y(20, 30); 143 | end; 144 | 145 | var 146 | F: TFoo; 147 | 148 | type 149 | TMyProc2 = procedure(Param1, Param2: Y) of object; 150 | TFoo = class 151 | procedure Test; 152 | procedure MyProc2(X, Y: T); 153 | end; 154 | 155 | procedure TFoo.MyProc2(X, Y: T); 156 | begin 157 | Write('MyProc2'); 158 | {$IFDEF CIL} 159 | Write(X.ToString); 160 | Write(', '); 161 | Writeln(Y.ToString); 162 | {$ENDIF} 163 | WR 164 | end; 165 | 166 | procedure TFoo.Test; 167 | var 168 | P : TMyProc2; 169 | X: TFoo; 170 | begin 171 | MyProc2('Hello', 'World'); //type specified 172 | MyProc2('Hello', 'World'); //inferred from argument type 173 | MyProc2(10, 20); 174 | MyProc2(10, 20); 175 | P := X.MyProc2; 176 | P(40, 50); 177 | end; 178 | 179 | var 180 | F: TFoo; 181 | 182 | type 183 | TFoo = class 184 | X: T; 185 | end; 186 | 187 | TBar = class(TFoo) 188 | Y: T; // error! unknown identifier "T" 189 | end; 190 | 191 | var 192 | F: TFoo; 193 | 194 | 195 | procedure TSynUNIXShellScriptSyn.MakeMethodTables; 196 | var 197 | I: Char; 198 | begin 199 | for I := #0 to #255 do 200 | case I of 201 | #34, #39{!@#$#39}: fProcTable[I] := {$IFDEF SYN_LAZARUS}@{$ENDIF}StringProc; 202 | '#': fProcTable[I] := {$IFDEF SYN_LAZARUS}@{$ENDIF}SlashProc; 203 | '{': fProcTable[I] := {$IFDEF SYN_LAZARUS}@{$ENDIF}BraceOpenProc; 204 | ';': fProcTable[I] := {$IFDEF SYN_LAZARUS}@{$ENDIF}PointCommaProc; 205 | '.': fProcTable[i] := {$IFDEF SYN_LAZARUS}@{$ENDIF}DotProc; 206 | #13: fProcTable[I] := {$IFDEF SYN_LAZARUS}@{$ENDIF}CRProc; 207 | 'A'..'Z', 'a'..'z', '_': fProcTable[I] := {$IFDEF SYN_LAZARUS}@{$ENDIF}IdentProc; 208 | #10: fProcTable[I] := {$IFDEF SYN_LAZARUS}@{$ENDIF}LFProc; 209 | #0: fProcTable[I] := {$IFDEF SYN_LAZARUS}@{$ENDIF}NullProc; 210 | '0'..'9': fProcTable[I] := {$IFDEF SYN_LAZARUS}@{$ENDIF}NumberProc; 211 | '(': fProcTable[I] := {$IFDEF SYN_LAZARUS}@{$ENDIF}RoundOpenProc; 212 | '/': fProcTable[I] := {$IFDEF SYN_LAZARUS}@{$ENDIF}SlashProc; 213 | '$': fProcTable[i] := {$IFDEF SYN_LAZARUS}@{$ENDIF}DollarProc; 214 | #1..#9, #11, #12, #14..#32: fProcTable[I] := {$IFDEF SYN_LAZARUS}@{$ENDIF}SpaceProc; 215 | else fProcTable[I] := {$IFDEF SYN_LAZARUS}@{$ENDIF}UnknownProc; 216 | end; 217 | end; 218 | 219 | begin 220 | end. 221 | -------------------------------------------------------------------------------- /Token.pas: -------------------------------------------------------------------------------- 1 | unit Token; 2 | 3 | interface 4 | 5 | type 6 | TTokenKind = (tkUndefined, tkIdentifier, tkStringConstant, tkCharConstant, tkIntegerConstant, tkRealConstant, 7 | tkConstantExpression, tkLabelIdentifier, tkTypeIdentifier, tkClassIdentifier, tkReservedWord, tkSpecialSymbol, 8 | tkParameter, tkProgram, tkUnit, tkLibrary, tkPackage, 9 | tkInteger, tkBoolean, tkByte, tkWord, tkCardinal, tkLongInt, tkInt64, tkUInt64, tkChar, 10 | tkWideChar, tkWideString, tkLongWord, tkShortInt, tkSmallInt, tkPChar, tkPointer, 11 | tkReal, tkSingle, tkDouble, tkExtended, tkCurrency, tkComp, tkByteBool, tkWordBool, tkLongBool); 12 | 13 | const 14 | Kinds : array[TTokenKind] of AnsiString = ( 15 | 'Undefined', 'Identifier', 'String Constant', 'Char Constant', 'Integer Constant', 16 | 'Real Constant', 'Constant Expression', 'Label Identifier', 'Type Identifier', 'Class Identifier', 'Reserved Word', 17 | 'Special Symbol', 'Parameter', 'Program', 'Unit', 'Library', 'Package', 18 | 'Integer', 'Boolean', 'Byte', 'Word', 'Cardinal', 'LongInt', 'Int64', 'UInt64', 'Char', 19 | 'WideChar', 'WideString', 'LongWord', 'ShortInt', 'SmallInt', 'PChar', 'Pointer', 20 | 'Real', 'Single', 'Double', 'Extended', 'Currency', 'Comp', 'ByteBool', 'WordBool', 'LongBool'); 21 | 22 | type 23 | TToken = class 24 | Lexeme : string; 25 | Hash : Cardinal; 26 | Type_ : TToken; 27 | NextScope : TToken; 28 | Scope : Word; 29 | Kind : TTokenKind; 30 | RealValue : Extended; 31 | IntegerValue : Int64; 32 | StringValue : string; 33 | end; 34 | 35 | implementation 36 | 37 | end. 38 | -------------------------------------------------------------------------------- /imagens/Cheetah_Dragon_by_Demon_of_night_wings.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wanderlan/llvm-pascal/19fda52906749ee0bd05d0e0c1d81d2806b7d263/imagens/Cheetah_Dragon_by_Demon_of_night_wings.jpg -------------------------------------------------------------------------------- /imagens/Spotted_Dragon_Line_Art_by_Demon_of_night_wings.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wanderlan/llvm-pascal/19fda52906749ee0bd05d0e0c1d81d2806b7d263/imagens/Spotted_Dragon_Line_Art_by_Demon_of_night_wings.jpg -------------------------------------------------------------------------------- /llvmTriple.pas: -------------------------------------------------------------------------------- 1 | (* 2 | LLVM Triple Class 3 | > Author: Aleksey A. Naumov [alexey.naumov@gmail.com] 4 | > License: BSD 5 | *) 6 | unit llvmTriple; 7 | 8 | interface 9 | 10 | uses 11 | SysUtils; 12 | 13 | type 14 | TArchType = ( 15 | atUnknownArch, 16 | atARM, 17 | atCellSPU, 18 | atHexagon, 19 | atMIPS, 20 | atMIPSel, 21 | atMIPS64, 22 | atMIPS64el, 23 | atMSP430, 24 | atPPC, 25 | atPPC64, 26 | atR600, 27 | atSparc, 28 | atSparCV9, 29 | atTCE, 30 | atThumb, 31 | atX86, 32 | atX86_64, 33 | atXCore, 34 | atMBlaze, 35 | atNVPTX, 36 | atNVPTX64, 37 | atLE32, 38 | atAMDil 39 | ); 40 | 41 | TArchRec = record 42 | Name: String; 43 | PBW: Cardinal; 44 | Alternate: TArchType; 45 | end; 46 | 47 | const 48 | CArchType: array [TArchType] of TArchRec = ( 49 | (Name: 'UnknownArch'; PBW: 0; Alternate: atUnknownArch), 50 | (Name: 'arm'; PBW: 32; Alternate: atARM), 51 | (Name: 'cellspu'; PBW: 32; Alternate: atCellSPU), 52 | (Name: 'hexagon'; PBW: 32; Alternate: atHexagon), 53 | (Name: 'mips'; PBW: 32; Alternate: atMIPS64), 54 | (Name: 'mipsel'; PBW: 32; Alternate: atMIPS64el), 55 | (Name: 'mips64'; PBW: 64; Alternate: atMIPS), 56 | (Name: 'mips64el'; PBW: 64; Alternate: atMIPSel), 57 | (Name: 'msp430'; PBW: 16; Alternate: atUnknownArch), 58 | (Name: 'ppc'; PBW: 32; Alternate: atPPC64), 59 | (Name: 'ppc64'; PBW: 64; Alternate: atPPC), 60 | (Name: 'r600'; PBW: 32; Alternate: atR600), 61 | (Name: 'sparc'; PBW: 32; Alternate: atSparcV9), 62 | (Name: 'sparcv9'; PBW: 64; Alternate: atSparc), 63 | (Name: 'tce'; PBW: 32; Alternate: atTCE), 64 | (Name: 'thumb'; PBW: 32; Alternate: atThumb), 65 | (Name: 'x86'; PBW: 32; Alternate: atX86_64), 66 | (Name: 'x86_64'; PBW: 64; Alternate: atX86), 67 | (Name: 'xcore'; PBW: 32; Alternate: atXCore), 68 | (Name: 'mblaze'; PBW: 32; Alternate: atMBlaze), 69 | (Name: 'nvptx'; PBW: 32; Alternate: atNVPTX64), 70 | (Name: 'nvptx64'; PBW: 64; Alternate: atNVPTX), 71 | (Name: 'le32'; PBW: 32; Alternate: atLE32), 72 | (Name: 'amdil'; PBW: 32; Alternate: atAMDil) 73 | ); 74 | 75 | type 76 | TVendorType = ( 77 | vtUnknownVendor, 78 | vtApple, 79 | vtPC, 80 | vtSCEI, 81 | vtBGP, 82 | vtBGQ 83 | ); 84 | 85 | const 86 | CVendorType: array [TVendorType] of String = ( 87 | 'UnknownVendor', 88 | 'Apple', 89 | 'PC', 90 | 'SCEI', 91 | 'BGP', 92 | 'BGQ' 93 | ); 94 | 95 | type 96 | TOSType = ( 97 | otUnknownOS, 98 | otAuroraUX, 99 | otCygwin, 100 | otDarwin, 101 | otDragonFly, 102 | otFreeBSD, 103 | otIOS, 104 | otKFreeBSD, 105 | otLinux, 106 | otLv2, 107 | otMacOSX, 108 | otMinGW32, 109 | otNetBSD, 110 | otOpenBSD, 111 | otSolaris, 112 | otWin32, 113 | otHaiku, 114 | otMinix, 115 | otRTEMS, 116 | otNativeClient, 117 | otCNK 118 | ); 119 | 120 | const 121 | COSType: array [TOSType] of String = ( 122 | 'UnknownOS', 123 | 'AuroraUX', 124 | 'Cygwin', 125 | 'Darwin', 126 | 'DragonFly', 127 | 'FreeBSD', 128 | 'IOS', 129 | 'KFreeBSD', 130 | 'Linux', 131 | 'Lv2', 132 | 'MacOSX', 133 | 'MinGW32', 134 | 'NetBSD', 135 | 'OpenBSD', 136 | 'Solaris', 137 | 'Win32', 138 | 'Haiku', 139 | 'Minix', 140 | 'RTEMS', 141 | 'NativeClient', 142 | 'CNK' 143 | ); 144 | 145 | type 146 | TEnvironmentType = ( 147 | etUnknownEnvironment, 148 | etGNU, 149 | etGNUEABI, 150 | etGNUEABIHF, 151 | etEABI, 152 | etMachO, 153 | etANDROIDEABI 154 | ); 155 | 156 | const 157 | CEnvironmentType: array [TEnvironmentType] of String = ( 158 | 'UnknownEnvironment', 159 | 'GNU', 160 | 'GNUEABI', 161 | 'GNUEABIHF', 162 | 'EABI', 163 | 'MachO', 164 | 'ANDROIDEABI' 165 | ); 166 | 167 | type 168 | TLLVMTriple = class 169 | private 170 | FArchType: TArchType; 171 | FVendorType: TVendorType; 172 | FOSType: TOSType; 173 | FEnvType: TEnvironmentType; 174 | FTriple: String; 175 | procedure BuildTriple; 176 | procedure ParseTriple; 177 | procedure SetArchType(const Value: TArchType); 178 | procedure SetEnvType(const Value: TEnvironmentType); 179 | procedure SetOSType(const Value: TOSType); 180 | procedure SetVendorType(const Value: TVendorType); 181 | procedure SetTriple(const Value: String); 182 | function GetArchTypeName: String; 183 | function GetEnvTypeName: String; 184 | function GetOSTypeName: String; 185 | function GetVendorTypeName: String; 186 | function GetArchPointerBitWidth: Cardinal; 187 | public 188 | constructor Create; overload; 189 | constructor Create(const ATriple: String); overload; 190 | constructor Create(AArchType: TArchType; AVendorType: TVendorType; 191 | AOSType: TOSType); overload; 192 | constructor Create(AArchType: TArchType; AVendorType: TVendorType; 193 | AOSType: TOSType; AEnvType: TEnvironmentType); overload; 194 | destructor Destroy; override; 195 | 196 | function IsArch16Bit: Boolean; 197 | function IsArch32Bit: Boolean; 198 | function IsArch64Bit: Boolean; 199 | function HasEnvironment: Boolean; 200 | 201 | function Get32BitArchVariant: TArchType; 202 | function Get64BitArchVariant: TArchType; 203 | 204 | procedure SwitchTo32BitArchVariant; 205 | procedure SwitchTo64BitArchVariant; 206 | public 207 | property Triple: String read FTriple write SetTriple; 208 | 209 | property ArchType: TArchType read FArchType write SetArchType; 210 | property VendorType: TVendorType read FVendorType write SetVendorType; 211 | property OSType: TOSType read FOSType write SetOSType; 212 | property EnvType: TEnvironmentType read FEnvType write SetEnvType; 213 | 214 | property ArchTypeName: String read GetArchTypeName; 215 | property VendorTypeName: String read GetVendorTypeName; 216 | property OSTypeName: String read GetOSTypeName; 217 | property EnvTypeName: String read GetEnvTypeName; 218 | 219 | property ArchPointerBitWidth: Cardinal read GetArchPointerBitWidth; 220 | end; 221 | 222 | implementation 223 | 224 | { TLLVMTriple } 225 | 226 | procedure TLLVMTriple.BuildTriple; 227 | begin 228 | FTriple := GetArchTypeName + '-' + 229 | GetVendorTypeName + '-' + 230 | GetOSTypeName; 231 | 232 | if HasEnvironment then 233 | FTriple := FTriple + '-' + GetEnvTypeName; 234 | end; 235 | 236 | constructor TLLVMTriple.Create(AArchType: TArchType; AVendorType: TVendorType; 237 | AOSType: TOSType); 238 | begin 239 | FArchType := AArchType; 240 | FVendorType := AVendorType; 241 | FOSType := AOSType; 242 | FEnvType := etUnknownEnvironment; 243 | FTriple := ''; 244 | BuildTriple; 245 | end; 246 | 247 | constructor TLLVMTriple.Create(AArchType: TArchType; AVendorType: TVendorType; 248 | AOSType: TOSType; AEnvType: TEnvironmentType); 249 | begin 250 | FArchType := AArchType; 251 | FVendorType := AVendorType; 252 | FOSType := AOSType; 253 | FEnvType := AEnvType; 254 | FTriple := ''; 255 | BuildTriple; 256 | end; 257 | 258 | constructor TLLVMTriple.Create; 259 | begin 260 | FArchType := atUnknownArch; 261 | FVendorType := vtUnknownVendor; 262 | FOSType := otUnknownOS; 263 | FEnvType := etUnknownEnvironment; 264 | FTriple := ''; 265 | BuildTriple; 266 | end; 267 | 268 | constructor TLLVMTriple.Create(const ATriple: String); 269 | begin 270 | FArchType := atUnknownArch; 271 | FVendorType := vtUnknownVendor; 272 | FOSType := otUnknownOS; 273 | FEnvType := etUnknownEnvironment; 274 | FTriple := ATriple; 275 | ParseTriple; 276 | end; 277 | 278 | destructor TLLVMTriple.Destroy; 279 | begin 280 | inherited; 281 | end; 282 | 283 | function TLLVMTriple.Get32BitArchVariant: TArchType; 284 | begin 285 | Result := FArchType; 286 | if (CArchType[FArchType].PBW <> 32) then 287 | Result := CArchType[FArchType].Alternate; 288 | end; 289 | 290 | function TLLVMTriple.Get64BitArchVariant: TArchType; 291 | begin 292 | Result := FArchType; 293 | if (CArchType[FArchType].PBW <> 64) then 294 | Result := CArchType[FArchType].Alternate; 295 | end; 296 | 297 | function TLLVMTriple.GetArchPointerBitWidth: Cardinal; 298 | begin 299 | Result := CArchType[FArchType].PBW; 300 | end; 301 | 302 | function TLLVMTriple.GetArchTypeName: String; 303 | begin 304 | Result := CArchType[FArchType].Name; 305 | end; 306 | 307 | function TLLVMTriple.GetEnvTypeName: String; 308 | begin 309 | Result := CEnvironmentType[FEnvType]; 310 | end; 311 | 312 | function TLLVMTriple.GetOSTypeName: String; 313 | begin 314 | Result := COSType[FOSType]; 315 | end; 316 | 317 | function TLLVMTriple.GetVendorTypeName: String; 318 | begin 319 | Result := CVendorType[FVendorType]; 320 | end; 321 | 322 | function TLLVMTriple.HasEnvironment: Boolean; 323 | begin 324 | Result := (FEnvType <> etUnknownEnvironment); 325 | end; 326 | 327 | function TLLVMTriple.IsArch16Bit: Boolean; 328 | begin 329 | Result := (GetArchPointerBitWidth = 16); 330 | end; 331 | 332 | function TLLVMTriple.IsArch32Bit: Boolean; 333 | begin 334 | Result := (GetArchPointerBitWidth = 32); 335 | end; 336 | 337 | function TLLVMTriple.IsArch64Bit: Boolean; 338 | begin 339 | Result := (GetArchPointerBitWidth = 64); 340 | end; 341 | 342 | procedure TLLVMTriple.ParseTriple; 343 | begin 344 | // ToDo: Parse FTriple to Arch/Vendor/OS/Environment 345 | raise Exception.Create('[ParseTriple] Not ready yet!'); 346 | end; 347 | 348 | procedure TLLVMTriple.SetArchType(const Value: TArchType); 349 | begin 350 | if (FArchType <> Value) then 351 | begin 352 | FArchType := Value; 353 | BuildTriple; 354 | end; 355 | end; 356 | 357 | procedure TLLVMTriple.SetEnvType(const Value: TEnvironmentType); 358 | begin 359 | if (FEnvType <> Value) then 360 | begin 361 | FEnvType := Value; 362 | BuildTriple; 363 | end; 364 | end; 365 | 366 | procedure TLLVMTriple.SetOSType(const Value: TOSType); 367 | begin 368 | if (FOSType <> Value) then 369 | begin 370 | FOSType := Value; 371 | BuildTriple; 372 | end; 373 | end; 374 | 375 | procedure TLLVMTriple.SetTriple(const Value: String); 376 | begin 377 | if (FTriple <> Value) then 378 | begin 379 | FTriple := Value; 380 | ParseTriple; 381 | end; 382 | end; 383 | 384 | procedure TLLVMTriple.SetVendorType(const Value: TVendorType); 385 | begin 386 | if (FVendorType <> Value) then 387 | begin 388 | FVendorType := Value; 389 | BuildTriple; 390 | end; 391 | end; 392 | 393 | procedure TLLVMTriple.SwitchTo32BitArchVariant; 394 | begin 395 | SetArchType(Get32BitArchVariant); 396 | end; 397 | 398 | procedure TLLVMTriple.SwitchTo64BitArchVariant; 399 | begin 400 | SetArchType(Get64BitArchVariant); 401 | end; 402 | 403 | end. 404 | -------------------------------------------------------------------------------- /readme.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wanderlan/llvm-pascal/19fda52906749ee0bd05d0e0c1d81d2806b7d263/readme.txt --------------------------------------------------------------------------------